Skip to content

On retries, attempts to reach netbox on port 80 even if https URL is configured #184

@antifuchs

Description

@antifuchs

I'm attempting to import into NETBOX_URL=https://netbox.redacted-domain.ts.net, and the importer definitely manages to create some device types; however it appears to run into a duplicate (I believe it's the console port named COM), and then aborts with the following:

:;    ./nb-dt-import.py --vendors unifi,cyberpower,startech,navepoint,sophos --verbose
[...]
Power Port Template Created: DC In 1 - Other - 25 - 20
Power Port Template Created: DC In 2 - Other - 25 - 21
Console Port Template Created: COM USB - USB Micro B - 25 - 20
Traceback (most recent call last):
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/connection.py", line 204, in _new_conn
    sock = connection.create_connection(
        (self._dns_host, self.port),
    ...<2 lines>...
        socket_options=self.socket_options,
    )
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
    ~~~~~~~~~~~~^^^^
ConnectionRefusedError: [Errno 61] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
        conn,
    ...<10 lines>...
        **response_kw,
    )
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/connectionpool.py", line 493, in _make_request
    conn.request(
    ~~~~~~~~~~~~^
        method,
        ^^^^^^^
    ...<6 lines>...
        enforce_content_length=enforce_content_length,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/connection.py", line 500, in request
    self.endheaders()
    ~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/python@3.14/3.14.0/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1333, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.14/3.14.0/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1093, in _send_output
    self.send(msg)
    ~~~~~~~~~^^^^^
  File "/opt/homebrew/Cellar/python@3.14/3.14.0/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1037, in send
    self.connect()
    ~~~~~~~~~~~~^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/connection.py", line 331, in connect
    self.sock = self._new_conn()
                ~~~~~~~~~~~~~~^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/connection.py", line 219, in _new_conn
    raise NewConnectionError(
        self, f"Failed to establish a new connection: {e}"
    ) from e
urllib3.exceptions.NewConnectionError: HTTPConnection(host='netbox.redacted-domain.ts.net', port=80): Failed to establish a new connection: [Errno 61] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/requests/adapters.py", line 644, in send
    resp = conn.urlopen(
        method=request.method,
    ...<9 lines>...
        chunked=chunked,
    )
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/connectionpool.py", line 841, in urlopen
    retries = retries.increment(
        method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    )
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/urllib3/util/retry.py", line 535, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='netbox.redacted-domain.ts.net', port=80): Max retries exceeded with url: /api/dcim/module-bay-templates/10/ (Caused by NewConnectionError("HTTPConnection(host='netbox.redacted-domain.ts.net', port=80): Failed to establish a new connection: [Errno 61] Connection refused"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/asf/Hacks/Device-Type-Library-Import/./nb-dt-import.py", line 54, in <module>
    main()
    ~~~~^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/./nb-dt-import.py", line 25, in main
    netbox.create_device_types(device_types)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/netbox_api.py", line 143, in create_device_types
    self.device_types.create_module_bays(device_type['module-bays'], dt.id)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/netbox_api.py", line 359, in create_module_bays
    self.handle.log_device_ports_created(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self.netbox.dcim.module_bay_templates.create(to_create), "Module Bay")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/log_handler.py", line 35, in log_device_ports_created
    + f'{port.type if hasattr(port, "type") else ""} - {port.device_type.id} - '
                      ~~~~~~~^^^^^^^^^^^^^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/pynetbox/core/response.py", line 303, in __getattr__
    if self.full_details():
       ~~~~~~~~~~~~~~~~~^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/pynetbox/core/response.py", line 459, in full_details
    self._parse_values(next(req.get()))
                       ~~~~^^^^^^^^^^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/pynetbox/core/query.py", line 293, in get
    req = self._make_call(add_params=add_params)
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/pynetbox/core/query.py", line 243, in _make_call
    req = getattr(self.http_session, verb)(
        url_override or self.url, headers=headers, params=params, json=data
    )
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/Users/asf/Hacks/Device-Type-Library-Import/venv/lib/python3.14/site-packages/requests/adapters.py", line 677, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='netbox.redacted-domain.ts.net', port=80): Max retries exceeded with url: /api/dcim/module-bay-templates/10/ (Caused by NewConnectionError("HTTPConnection(host='netbox.redacted-domain.ts.net', port=80): Failed to establish a new connection: [Errno 61] Connection refused"))

I can't find anything about retries in this tool, so maybe the issue is in pynetbox? But it seems incorrect to downgrade the port to 80 either way.

This is connecting to netbox v4.4.9.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions