netbox-community / Device-Type-Library-Import

This library is intended to assist with importing device and module types into NetBox from the NetBox Community DeviceType-Library
https://github.com/netbox-community/devicetype-library
MIT License
255 stars 76 forks source link

import py fails with a 403 Authentication credentials were not provided. ignores NETBOX_TOKEN #144

Open julianfirminger-united opened 1 month ago

julianfirminger-united commented 1 month ago

nb-dt-import.py fails with a 403. It seems to us it's ignoring the .env file?
I have a previous version running on rocky9.3 that works fine, we cant see a conf difference between them.
new nb4 on rokey9.4 does this:

Package devicetype-library is already installed, updating /opt/Device-Type-Library-Import/repo
Traceback (most recent call last):
  File "/opt/Device-Type-Library-Import/./nb-dt-import.py", line 54, in <module>
    main()
  File "/opt/Device-Type-Library-Import/./nb-dt-import.py", line 17, in main
    netbox = NetBox(settings)
  File "/opt/Device-Type-Library-Import/netbox_api.py", line 28, in __init__
    self.verify_compatibility()
  File "/opt/Device-Type-Library-Import/netbox_api.py", line 50, in verify_compatibility
    version_split = [int(x) for x in self.netbox.version.split('.')]
  File "/opt/Device-Type-Library-Import/venv/lib64/python3.9/site-packages/pynetbox/core/api.py", line 106, in version
    version = Request(
  File "/opt/Device-Type-Library-Import/venv/lib64/python3.9/site-packages/pynetbox/core/query.py", line 187, in get_version
    raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 403 Forbidden: {'detail': 'Authentication credentials were not provided.'}

Netbox runs fine, there is an api user with a token enabled. the .env file looks like:

NETBOX_URL=http://<netbox_url>
NETBOX_TOKEN=<token>
REPO_URL=https://github.com/netbox-community/devicetype-library.git
REPO_BRANCH=master
IGNORE_SSL_ERRORS=True
#SLUGS=c9300-48u isr4431 isr4331
ale456-1 commented 1 month ago

Hi @julianfirminger-united.

I had the same error. In my case, i changed the version of pynetbox, from 7.0.1 to 7.3.4 and it started to work, using this command inside my virtual-env:

pip install --force-reinstall -v "pynetbox==7.3.4"

The difference is located in: [7.0.1]pynetbox/core/query.py:184 vs [7.3.4]pynetbox/core/query.py:196

Hope it can help.

julianfirminger-united commented 1 month ago

@ale456-1 turns out it needed more than that. the installer cant handle the new version number post v4 as it has 3 parts. 4.0.1 etc.
See thisfor the fix: [((https://github.com/netbox-community/Device-Type-Library-Import/issues/142))]

kniteli commented 2 weeks ago

@julianfirminger-united if you have valid ssl certs there's no issue, you can just run the install mentioned above. I highly recommend spending the 5 bucks a year to grab any old domain and taking the 10 minutes to generate a letsencrypt cert. My registrar has those off brand ones for $1 per year actually

PadawanDeluxe commented 2 weeks ago

Hi there, I can confirm workaround to reinstall pynetbox query per command

pip install --force-reinstall -v "pynetbox==7.3.4"

Quoting out the verification of Netbox version did not help me at this point. I switched backed and reinstalled pynetbox package so I am good to go right now.

regards Carsten