You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
API unable to authenticate after updating Inventree #233
After I recently updated Inventree to the latest stable version and the API to 0.14.0 all my API based scripts have problems authenticating yielding a server connection issue. More precisely I get the following error:
Server connection error: <class 'requests.exceptions.ConnectionError'>
InvenTree server is not connected. Skipping authentication check
Traceback (most recent call last):
File "/Users/jefo/MEGA/Electronics/PowerGaard/kicad/database/pgdb/mwe.py", line 4, in <module>
api = InvenTreeAPI("http://inventree.localhost", username="root", password="jefo123")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jefo/anaconda3/lib/python3.11/site-packages/inventree/api.py", line 77, in __init__
self.connect()
File "/Users/jefo/anaconda3/lib/python3.11/site-packages/inventree/api.py", line 131, in connect
raise ConnectionError("Authentication at InvenTree server failed")
ConnectionError: Authentication at InvenTree server failed
I've gone down to a minimum example of the following code, where I have replaced username and password:
I have also tried accessing with a token that worked last week on an older version of Inventree (v14.2 I believe it was). I am wondering why it states: 'InvenTree server is not connected.' because I have access to it on the new platform https://inventree.localhost/platform or the old GUI on https://inventree.localhost.
I have similarly tried accessing with pots 1337 and 8000 but unsurprisingly they do not work, as I have not specified any specific link in the INVENTREE_URL_SITE environment variable. Switching between http and https and using other combinations for the server address such as <URL>/api, <URL>/platform/api etc. similarly yield nothing.
Do you have any ideas what's going on?
Version info
Macos Monterey: 12.7.5
Inventree source code SHA: 9f35971db17e1660fcd27c752558d41952a3e541
Inventree API: 0.14.0
Docker:
@SchrodingersGat yes naturally, the latest paste was from one of the tries that I've been running with. Whether it's http or https is no different in the functionality, but I'd expect it should match up with the server instance that uses https.
@JacobEFO apologies, I missed the last part where you had already tried that.
Looking at the initial error message it is stating an authentication error - this means the username / password combination is incorrect. Incidentally you should remove that data from your post
I had verified numerous times that both the 'root' user with its accompanying password and my local super user with its respective password could indeed log in on the webpage but would fail authentication on the API. Similarly using a token that had previously been used successfully for authentication prior to updating Inventree failed with the same error.
I've got exactly the same issue
Web access login works fine, password double and triple checked
python api using token or basic logon fails with "Authentication at InvenTree server failed"
I have still yet to find a resolution. At the moment I put my inventree work on the shelf and hope to return in a newer version where this bug might just be miraculously solved :)
Solved for my setup.
Had to add "WSGIPAssAuthorization On" to the apache config.
Authorization header wasn't getting sent thru.
Thou I tried a coupe of other things as well on the way.
Downgrade to python 3.11 (from 3.12). Haven't tried 3.12 again.
pulled the latest changes on stable to 0.15.4 / fa1a9da23a86a1cc6bea29e647c268872a15dcb1
reinstalled the python venv and reset the database to initial setup.
played with a couple of setting in the config.yaml related to cookies.
"invoke server" worked ok which suggested an apache config issue.
@JacobEFO, The following patch helped debug the issue for me.
diff --git a/src/backend/InvenTree/InvenTree/middleware.py b/src/backend/InvenTree/InvenTree/middleware.py
index d5463af22..c5b422342 100644
--- a/src/backend/InvenTree/InvenTree/middleware.py
+++ b/src/backend/InvenTree/InvenTree/middleware.py
@@ -70,6 +70,7 @@ class AuthRequiredMiddleware(object):
# API requests are handled by the DRF library
if request.path_info.startswith('/api/'):
+ print(f"{request.headers}")
response = self.get_response(request)
return response
It appears that maybe doing subdomain requests against "localhost" (e.g. inventree.localhost) is not supported by the python requests library: psf/requests#5847
If you use a locally bound IP address of your machine as the INVENTREE_SITE_URL, then you should (hopefully) be able to get access?
e.g. INVENTREE_SITE_URL=http://192.168.120.10 (but use an actual valid IP for your machine)...
which sounds helpful but I don't know how/where to enable that option to try it. Nor have I figured out where to add "WSGIPAssAuthorization On" in order to try that. I have confirmed that Ki-nTree has no errors when I try to connect to the test server you listed above.
And truth-be-told I have no idea if this is an issue that needs to be fixed/tweaked in my install on the Ki-nTree side or the Inventree side and/or if it's something that should be changed in either of those code bases. Feel free to help me better understand if you feel inspired to do so. I'd love to better understand. Thanks.
@SchrodingersGat Thanks for getting back to me. I successfully cloned Ki-nTree, made your suggested change, and confirmed the code with the change was actually run but, alas, I still have the same behavior so I'm still in search of things to try.
@SchrodingersGat I think I got all the right pieces in place but I'm still not there. The error message did get longer...
`/home/steve/.local/lib/python3.10/site-packages/pip_system_certs/wrapt_requests.py:71: UserWarning: Failed to patch SSL settings for unverified requests (unsupported version of urllib3?)
This may lead to errors when urllib3 tries to modify verify_mode.
Please report an issue at https://gitlab.com/alelec/pip-system-certs with your
python version included in the description
warnings.warn(
Server connection error: <class 'requests.exceptions.ConnectionError'>
InvenTree server is not connected. Skipping authentication check
[TREE] Error connecting to InvenTree server: invalid address, username or password
`
@SchrodingersGat
urllib3 1.26.5
One other thing of note. The install of Ki-nTree does install inventree but it doesn't appear to install inventree-python (at least its not visible in either pip list or in the ki-nTree requirements.txt. This was a surprise to me. The code does include (with the addition you requested):
I'm now on urllib3 v2.3.0 and still having the issue.
`/home/steve/.local/lib/python3.10/site-packages/pip_system_certs/wrapt_requests.py:71: UserWarning: Failed to patch SSL settings for unverified requests (unsupported version of urllib3?)
This may lead to errors when urllib3 tries to modify verify_mode.
Please report an issue at https://gitlab.com/alelec/pip-system-certs with your
python version included in the description
warnings.warn(
Server connection error: <class 'requests.exceptions.ConnectionError'>
InvenTree server is not connected. Skipping authentication check
[TREE] Error connecting to InvenTree server: invalid address, username or password`
At this point, I've punted. I wish I had the skills in this area to help debug this as I think my attempted configuration should be fairly common. That said, my work-around was to bring Inventree up on a re-purposed laptop which is now running native Ubuntu (still using the docker configuration) and, Ki-nTree (on my original machine) has no trouble connecting to it. Obviously, I'd rather be running both Ki-nTree and Inventree on the same machine but this approach isn't too painful.
@anotherstevest2 sorry, I'm at a loss too at this point. I have had success using the python interface against multiple HTTPS servers. Perhaps there is something odd or particular to your server certificates? Unfortunately I have no further suggestions for you at this stage
curl and the browser could access http://inventree.localhost just fine, but Python (requests, socket.getaddrinfo, etc.) failed with:
NameResolutionError("HTTPConnection(host='inventree.localhost', port=80): Failed to resolve 'inventree.localhost' ([Errno -2] Name or service not known)"
So it seems like a DNS resolving issue and somehow the requests call isn't being sent to Caddy?. You can test a quick fix by adding
Shot in the dark, and it's an older topic so maybe @anotherstevest2 and @JacobEFO you're onto other things, but I also fought the same authenticatin failure for the Python api, ConnectionError: Authentication at InvenTree server failed
with a newly generated API token and self-signed cert.
Tried credentials, tried other user API tokens, tried the IP, and added "strict=False" to the InvenTreeAPI call. The demo worked, but my own site did not. Out of the blue I let vscode autocomplete the URL line's "host="...and it suddenly authenticated. Plus, now it keeps on working even after removing "host=" from the line. api = InvenTreeAPI( host="https://my.inventree.hostname", token="inv-blah-blah", strict=False
Figured i might as well throw this out there just in case, but maybe it's unrelated to whatever kicked it to start working. In my case the direct IP doesn't work.
Activity
SchrodingersGat commentedon Jun 9, 2024
These two should be the same.
JacobEFO commentedon Jun 9, 2024
@SchrodingersGat yes naturally, the latest paste was from one of the tries that I've been running with. Whether it's
httporhttpsis no different in the functionality, but I'd expect it should match up with the server instance that useshttps.SchrodingersGat commentedon Jun 9, 2024
@JacobEFO apologies, I missed the last part where you had already tried that.
Looking at the initial error message it is stating an authentication error - this means the username / password combination is incorrect. Incidentally you should remove that data from your post
JacobEFO commentedon Jun 9, 2024
I had verified numerous times that both the 'root' user with its accompanying password and my local super user with its respective password could indeed log in on the webpage but would fail authentication on the API. Similarly using a token that had previously been used successfully for authentication prior to updating Inventree failed with the same error.
SchrodingersGat commentedon Jun 9, 2024
That is very odd. I have just confirmed that the latest inventree-python lib works with a local setup and also the demo server.
Can you check if you can connect to:
https://demo.inventree.orgadmininventree(using your current python setup)
JacobEFO commentedon Jun 9, 2024
I can successfully log-in through the web-page but also gain access using the API using username/password.
So I might just conclude, this is an inventree installation/setup problem more than the API at least.
reid-p commentedon Jun 24, 2024
I've got exactly the same issue
Web access login works fine, password double and triple checked
python api using token or basic logon fails with "Authentication at InvenTree server failed"
JacobEFO commentedon Jun 24, 2024
I have still yet to find a resolution. At the moment I put my inventree work on the shelf and hope to return in a newer version where this bug might just be miraculously solved :)
SchrodingersGat commentedon Jun 24, 2024
@reid-p @JacobEFO have you tested access against the demo server?
reid-p commentedon Jun 25, 2024
Yes the demo works.
I can see the creds being sent in the headers, so seems to be a server side issue.
I'm using inventree-python 0.14, installed via pip.
Here's the details of my server:
Version Information:
InvenTree-Version: 0.15.3
Django Version: 4.2.12
Commit Hash: d4d9aa9
Commit Date: 2024-05-28
Commit Branch: stable
Database: mysql
Debug-Mode: True
Deployed using Docker: False
Platform: Linux-5.14.0-427.18.1.el9_4.x86_64-x86_64-with-glibc2.34
Installer: GIT
Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.0.0'}, {'name': 'InvenTreeCoreNotificationsPlugin', 'slug': 'inventreecorenotificationsplugin', 'version': '1.0.0'}, {'name': 'InvenTreeCurrencyExchange', 'slug': 'inventreecurrencyexchange', 'version': '1.0.0'}, {'name': 'InvenTreeLabel', 'slug': 'inventreelabel', 'version': '1.0.0'}, {'name': 'InvenTreeLabelMachine', 'slug': 'inventreelabelmachine', 'version': '1.0.0'}, {'name': 'InvenTreeLabelSheet', 'slug': 'inventreelabelsheet', 'version': '1.0.0'}, {'name': 'DigiKeyPlugin', 'slug': 'digikeyplugin', 'version': '1.0.0'}, {'name': 'LCSCPlugin', 'slug': 'lcscplugin', 'version': '1.0.0'}, {'name': 'MouserPlugin', 'slug': 'mouserplugin', 'version': '1.0.0'}, {'name': 'TMEPlugin', 'slug': 'tmeplugin', 'version': '1.0.0'}]
SchrodingersGat commentedon Jun 25, 2024
Ok, so the demo server is running "master" branch, whereas you are running "stable". Perhaps there is a difference there
reid-p commentedon Jun 26, 2024
Solved for my setup.
Had to add "WSGIPAssAuthorization On" to the apache config.
Authorization header wasn't getting sent thru.
Thou I tried a coupe of other things as well on the way.
Downgrade to python 3.11 (from 3.12). Haven't tried 3.12 again.
pulled the latest changes on stable to 0.15.4 / fa1a9da23a86a1cc6bea29e647c268872a15dcb1
reinstalled the python venv and reset the database to initial setup.
played with a couple of setting in the config.yaml related to cookies.
"invoke server" worked ok which suggested an apache config issue.
@JacobEFO, The following patch helped debug the issue for me.
JacobEFO commentedon Jun 26, 2024
Thanks for following up. However, I seem to have no luck at all still.
Where did you add the
WSGIPAssAuthorization Onflag?9 remaining items
SchrodingersGat commentedon Sep 10, 2024
@JacobEFO OK I might have something here...
It appears that maybe doing subdomain requests against "localhost" (e.g.
inventree.localhost) is not supported by the python requests library: psf/requests#5847If you use a locally bound IP address of your machine as the
INVENTREE_SITE_URL, then you should (hopefully) be able to get access?e.g.
INVENTREE_SITE_URL=http://192.168.120.10(but use an actual valid IP for your machine)...anotherstevest2 commentedon Mar 26, 2025
@SchrodingersGat I've just posted a request for help on reddit re a similar error from a new install when trying to setup Ki-nTree: https://www.reddit.com/r/InvenTree/comments/1jkc0ma/inventree_api_login_from_kintree_inventree_server/
and I don't know if my issue is the same as this one or something that just looks similar. If you think it's the same, I'm happy to move my concern here if that makes sense to you. I did try:
without success. I also saw:
which sounds helpful but I don't know how/where to enable that option to try it. Nor have I figured out where to add "WSGIPAssAuthorization On" in order to try that. I have confirmed that Ki-nTree has no errors when I try to connect to the test server you listed above.
And truth-be-told I have no idea if this is an issue that needs to be fixed/tweaked in my install on the Ki-nTree side or the Inventree side and/or if it's something that should be changed in either of those code bases. Feel free to help me better understand if you feel inspired to do so. I'd love to better understand. Thanks.
SchrodingersGat commentedon Mar 26, 2025
@anotherstevest2 to test the "bypass strict HTTPS" mode, initialize the API call like thus:
Hopefully that helps
anotherstevest2 commentedon Mar 27, 2025
@SchrodingersGat Thanks for getting back to me. I successfully cloned Ki-nTree, made your suggested change, and confirmed the code with the change was actually run but, alas, I still have the same behavior so I'm still in search of things to try.
SchrodingersGat commentedon Mar 27, 2025
@anotherstevest2 I just released
0.17.5which includes this fix - #265Please update your
inventree-pythoninstallation and LMK if the issue is addressed.anotherstevest2 commentedon Mar 27, 2025
@SchrodingersGat I think I got all the right pieces in place but I'm still not there. The error message did get longer...
`/home/steve/.local/lib/python3.10/site-packages/pip_system_certs/wrapt_requests.py:71: UserWarning: Failed to patch SSL settings for unverified requests (unsupported version of urllib3?)
This may lead to errors when urllib3 tries to modify verify_mode.
Please report an issue at https://gitlab.com/alelec/pip-system-certs with your
python version included in the description
warnings.warn(
Server connection error: <class 'requests.exceptions.ConnectionError'>
InvenTree server is not connected. Skipping authentication check
[TREE] Error connecting to InvenTree server: invalid address, username or password
`
SchrodingersGat commentedon Mar 27, 2025
Can you please LMK what version of
urllib3you are running:anotherstevest2 commentedon Mar 28, 2025
@SchrodingersGat
urllib3 1.26.5
One other thing of note. The install of Ki-nTree does install inventree but it doesn't appear to install inventree-python (at least its not visible in either pip list or in the ki-nTree requirements.txt. This was a surprise to me. The code does include (with the addition you requested):
from inventree.api import InvenTreeAPI ... return InvenTreeAPI(server, username=username, password=password, proxies=proxies, token=token, strict=False)anotherstevest2 commentedon Mar 28, 2025
P.S. My response time is about to slow way down as I've got some travel...
SchrodingersGat commentedon Mar 28, 2025
Ok, try running
pip install -U urllib3- I am on v2.3.0anotherstevest2 commentedon Mar 29, 2025
I'm now on urllib3 v2.3.0 and still having the issue.
`/home/steve/.local/lib/python3.10/site-packages/pip_system_certs/wrapt_requests.py:71: UserWarning: Failed to patch SSL settings for unverified requests (unsupported version of urllib3?)
This may lead to errors when urllib3 tries to modify verify_mode.
Please report an issue at https://gitlab.com/alelec/pip-system-certs with your
python version included in the description
warnings.warn(
Server connection error: <class 'requests.exceptions.ConnectionError'>
InvenTree server is not connected. Skipping authentication check
[TREE] Error connecting to InvenTree server: invalid address, username or password`
anotherstevest2 commentedon Apr 9, 2025
At this point, I've punted. I wish I had the skills in this area to help debug this as I think my attempted configuration should be fairly common. That said, my work-around was to bring Inventree up on a re-purposed laptop which is now running native Ubuntu (still using the docker configuration) and, Ki-nTree (on my original machine) has no trouble connecting to it. Obviously, I'd rather be running both Ki-nTree and Inventree on the same machine but this approach isn't too painful.
SchrodingersGat commentedon Apr 9, 2025
@anotherstevest2 sorry, I'm at a loss too at this point. I have had success using the python interface against multiple HTTPS servers. Perhaps there is something odd or particular to your server certificates? Unfortunately I have no further suggestions for you at this stage
smahm006 commentedon Jun 14, 2026
Ran into the same issue today.
curl and the browser could access http://inventree.localhost just fine, but Python (requests, socket.getaddrinfo, etc.) failed with:
So it seems like a DNS resolving issue and somehow the requests call isn't being sent to Caddy?. You can test a quick fix by adding
To /etc/hosts and trying again.
Not sure what the proper solution is but at least I got something working locally....
Carabela-del-Cielo commentedon Jul 27, 2026
Shot in the dark, and it's an older topic so maybe @anotherstevest2 and @JacobEFO you're onto other things, but I also fought the same authenticatin failure for the Python api,
ConnectionError: Authentication at InvenTree server failed
with a newly generated API token and self-signed cert.
Tried credentials, tried other user API tokens, tried the IP, and added "strict=False" to the InvenTreeAPI call. The demo worked, but my own site did not. Out of the blue I let vscode autocomplete the URL line's "host="...and it suddenly authenticated. Plus, now it keeps on working even after removing "host=" from the line.
api = InvenTreeAPI( host="https://my.inventree.hostname", token="inv-blah-blah", strict=FalseFigured i might as well throw this out there just in case, but maybe it's unrelated to whatever kicked it to start working. In my case the direct IP doesn't work.