netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
580 stars 172 forks source link

Keep getting Connection Reset #594

Closed rostskadat closed 11 months ago

rostskadat commented 12 months ago

pynetbox version

v7.2.0

NetBox version

v3.0.12

Python version

3.10

Steps to Reproduce

  1. Get an API:

    nb = pynetbox.api(args.api_url, token=args.token)
  2. Create a VRF:

vrf = nb.ipam.vrfs.create(name="name", description="description")
  1. Then try to obtain a cluster id
cluster_id = nb.virtualization.clusters.filter(cluster=cluster).__next__().id

This fails with a ConnectionResetError:

ERROR | ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Traceback (most recent call last):
  File "/home/rostskadat/git/upworks/Freelance-73-Gitlab-CICD/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/home/rostskadat/git/upworks/Freelance-73-Gitlab-CICD/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
  File "/project/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
  File "/usr/lib/python3.10/http/client.py", line 1375, in getresponse
    response.begin()
  File "/usr/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

Expected Behavior

The error is intermittent. If I add an HTTPAdapter with a retry then it eventually works fine.

Observed Behavior

A ConnectionResetError was raised

markkuleinio commented 11 months ago

I'd suggest moving this issue to a discussion as pynetbox does not raise ConnectionResetErrors, so the user needs some other help with the system.

There is no mention about the runtime environment but the output is not from from a pure cluster_id = ... statement.

rostskadat commented 11 months ago

Hello @markkuleinio ,

Thanks for your reply. I did some more digging and found out that the problem is in fact related to the uwsgi used to run the server. There is a discussion over at lae/ansible-role-netbox about this. And the work around did solve the problem. I'm therefore closing the issue.