Forums

(Caused by NewConnectionError('<urllib3.conn ection.VerifiedHTTPSConnection object at 0x7f8b9cc61b00>: Failed to establish a new connection: [Errno 111] Connection refused')

Hello,

I'm trying to do something with localbitcoins.com API but i get this error:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/urllib3/connection.py", line 171, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3.7/site-packages/urllib3/util/connection.py", line 79, in create_connection
    raise err
  File "/usr/lib/python3.7/site-packages/urllib3/util/connection.py", line 69, 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 "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.7/site-packages/urllib3/connection.py", line 314, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.7/site-packages/urllib3/connection.py", line 180, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f8b9cc61b00>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='localbitcoins.com', port=443): Max retries exceeded with url: /bitcoinaverage/ticker-all-currencies/ (Caused by NewConnectionError('<urllib3.connect
ion.VerifiedHTTPSConnection object at 0x7f8b9cc61b00>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in getAveragePrices
  File "/home/Chuox/.local/lib/python3.7/site-packages/lbcapi3/api.py", line 142, in call
    response = session.send(api_request, stream=stream)
  File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='localbitcoins.com', port=443): Max retries exceeded with url: /bitcoinaverage/ticker-all-currencies/ (Caused by NewConnectionError('<urllib3.conn
ection.VerifiedHTTPSConnection object at 0x7f8b9cc61b00>: Failed to establish a new connection: [Errno 111] Connection refused'))

wonder waht can it be.

[edit by admin: formatting]

I'm a free user, I think it has something to do with localbitcoins.com not being white listed. Anyone knows it this could be solved with a hacker account? Thanks

If you provide a link to the API's documentation, then the staff can add it to the whitelist.

Yes, it would almost certainly be solved with a hacker account -- they have unrestricted access to the external Internet, so the only case in which it would not work would be if localbitcoins were blocking access from our servers, which is unlikely (though not completely impossible).

However -- we do have localbitcoins.com on the whitelist already, so I think the problem is the specific code you're using to connect to it. Free accounts need to use a proxy server to make their outbound connections; if you use the requests library instead of using urllib3 directly, then it will automatically pick up the proxy details and do it all for you transparently.

Thanks for your answers, I think the problem is I'm not using the official library, I'm using this one that is python 3 compatible: https://github.com/6ones/lbcapi3

The library that you use needs to support using a proxy for the connection and you need to configure it to use the proxy. Check the docs for the library to see if it supports it and how to configure it and check http://help.pythonanywhere.com/pages/403ForbiddenError/ for the details.