Forums

Connection Aborted when calling an API

Hi,

I call an API using the requests module, specifically the Woo Commerce API. Some API requests work okay, but when it randomly just aborts the connection. I don't know if this is a python anywhere issue. Any help would be great. Here is the error log:

    Traceback (most recent call last):
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connection.py", line 416, in connect
    self.sock = ssl_wrap_socket(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/util/retry.py", line 532, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/connection.py", line 416, in connect
    self.sock = ssl_wrap_socket(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(0, 'Error'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atlsoft/commercelink/apps/AVWOITEMS.py", line 61, in <module>
    start(user)
  File "/home/atlsoft/commercelink/apps/AVWOITEMS.py", line 52, in start
    batch_items["create"].append(product_check(item))
  File "/home/atlsoft/commercelink/apps/AVWOITEMS.py", line 31, in product_check
    return woo.create_product(wooapi, item, category_id)
  File "/home/atlsoft/commercelink/platforms/woo/woo.py", line 177, in create_product
    tag = search_tag(word, api_object)
  File "/home/atlsoft/commercelink/platforms/woo/woo.py", line 65, in search_tag
    tag_search = api_object.get(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/woocommerce/api.py", line 106, in get
    return self.__request("GET", endpoint, None, **kwargs)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/woocommerce/api.py", line 92, in __request
    return request(
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/home/atlsoft/.virtualenvs/commercelink-virtualenv/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

It's not a very helpful error message. The only thing I can suggest is to try different versions of requests. It may be either that the site is using older protocols that are no longer supported by the version of requests that you're using or it could be the opposite - the version of requests that you're using is too old and the site is using newer versions of protocols that are not available in the requests that you're using.

Okay I'll give that ago, the error is so annoying because it's not really useful. I just want to confirm that it isn't a python anywhere issue on your end?

No, it is not