Posting Content to Friendica using Python
<p>I'm working on a project that is written in Python and needs to post updates to a Friendica server and interact using various APIs available. However, I have had very limited API usage experience and so I'm unsure of how to code this functionality in Python. There is an example on the Friendica GitHub however the Python example would not work for me. There is a Python3 module <a href="https://bitbucket.org/tobiasd/python-friendica/overview" rel="nofollow">https://bitbucket.org/tobiasd/python-friendica/overview</a>, however when trying to connect using this in a test script as follows:</p>

<pre><code>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import friendica
# make a new instance of friendica
f = friendica.friendica (server = '10.211.55.23/api/statuses/update', username = 'newtest', password = 'klaup8744')

# check that we are logged in
f.account_verify_credentials()

# get the current notifications
print (f.ping())

# post something with the default settings
f.statuses_update( status = "here is the message you are going to post" )
</code></pre>

<p>it would refuse the connection with the following message:</p>

<pre><code>Traceback (most recent call last):
  File "/usr/lib/python3.4/urllib/request.py", line 1182, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.4/http/client.py", line 1088, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1126, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1084, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 922, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 857, in send
    self.connect()
  File "/usr/lib/python3.4/http/client.py", line 1223, in connect
    super().connect()
  File "/usr/lib/python3.4/http/client.py", line 834, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python3.4/socket.py", line 512, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 503, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_1.py", line 12, in &lt;module&gt;
    print (f.ping())
  File "/home/sambraidley/Desktop/friendica.py", line 851, in ping
    res = urlopen(self.protocol()+self.apipath[:-4]+'/ping').read().decode('utf-8')
  File "/usr/lib/python3.4/urllib/request.py", line 161, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.4/urllib/request.py", line 463, in open
    response = self._open(req, data)
  File "/usr/lib/python3.4/urllib/request.py", line 481, in _open
    '_open', req)
  File "/usr/lib/python3.4/urllib/request.py", line 441, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 1225, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/lib/python3.4/urllib/request.py", line 1184, in do_open
    raise URLError(err)
urllib.error.URLError: &lt;urlopen error [Errno 111] Connection refused&gt;
</code></pre>

<p>The friendica Python3 module can be found at the following <a href="https://bitbucket.org/tobiasd/python-friendica/src/b0b75ae80a6e747e8724b1ae36972ebfd939beb5/friendica.py?fileviewer=file-view-default" rel="nofollow">https://bitbucket.org/tobiasd/python-friendica/src/b0b75ae80a6e747e8724b1ae36972ebfd939beb5/friendica.py?fileviewer=file-view-default</a></p>

<p>My Friendica server is setup within a VM with the address 10.211.55.23, with test credentials of username = 'newtest' and password 'klaup8744' and it is fully working as using the curl example code to post an update worked perfectly, as follows:</p>

<pre><code>/usr/bin/curl -u newtest:klaup8744 10.211.55.23/api/statuses/update.xml -d source="Testing" -d status="This is a test status"
</code></pre>

<p>According to the <a href="https://bitbucket.org/tobiasd/python-friendica/src/b0b75ae80a6e747e8724b1ae36972ebfd939beb5/friendica.py?fileviewer=file-view-default" rel="nofollow">source link</a> you posted, friendica uses https by default.  Your successful curl request is using http.<br>
Try instantiating friendica it using http:</p>

<pre><code>f = friendica.friendica (server = '10.211.55.23/api/statuses/update', 
username = 'newtest', password = 'klaup8744', useHTTPS=False)
</code></pre>

python api