GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — API unable to authenticate after updating Inventree · Issue #233 · inventree/inventree-python

API unable to authenticate after updating Inventree #233

New issue
Copy link
New issue
Copy link
Open
Open
API unable to authenticate after updating Inventree#233
Copy link
Labels
questionFurther information is requested

Description

@JacobEFO
JacobEFO
opened on Jun 9, 2024
Issue body actions

Hi,

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:

from inventree.api import InvenTreeAPI

if __name__ == "__main__":
    api = InvenTreeAPI("http://inventree.localhost", username="username", password="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:
image

Activity

Next
  1. SchrodingersGat commented on Jun 9, 2024

    @SchrodingersGat
    SchrodingersGat
    on Jun 9, 2024
    Member
    More actions

    image

    These two should be the same.

  2. JacobEFO commented on Jun 9, 2024

    @JacobEFO
    JacobEFO
    on Jun 9, 2024
    Author
    More actions

    @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.

  3. SchrodingersGat commented on Jun 9, 2024

    @SchrodingersGat
    SchrodingersGat
    on Jun 9, 2024
    Member
    More actions

    @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

  4. JacobEFO commented on Jun 9, 2024

    @JacobEFO
    JacobEFO
    on Jun 9, 2024
    Author
    More actions

    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.

  5. SchrodingersGat
    added
    questionFurther information is requested
    on Jun 9, 2024
  6. SchrodingersGat commented on Jun 9, 2024

    @SchrodingersGat
    SchrodingersGat
    on Jun 9, 2024
    Member
    More actions

    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:

    • host: https://demo.inventree.org
    • username: admin
    • password: inventree

    (using your current python setup)

  7. JacobEFO commented on Jun 9, 2024

    @JacobEFO
    JacobEFO
    on Jun 9, 2024
    Author
    More actions

    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.

  8. reid-p commented on Jun 24, 2024

    @reid-p
    reid-p
    on Jun 24, 2024
    More actions

    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"

  9. JacobEFO commented on Jun 24, 2024

    @JacobEFO
    JacobEFO
    on Jun 24, 2024
    Author
    More actions

    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 :)

  10. SchrodingersGat commented on Jun 24, 2024

    @SchrodingersGat
    SchrodingersGat
    on Jun 24, 2024
    Member
    More actions

    @reid-p @JacobEFO have you tested access against the demo server?

  11. reid-p commented on Jun 25, 2024

    @reid-p
    reid-p
    on Jun 25, 2024
    More actions

    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'}]

  12. SchrodingersGat commented on Jun 25, 2024

    @SchrodingersGat
    SchrodingersGat
    on Jun 25, 2024
    Member
    More actions

    Ok, so the demo server is running "master" branch, whereas you are running "stable". Perhaps there is a difference there

  13. reid-p commented on Jun 26, 2024

    @reid-p
    reid-p
    on Jun 26, 2024
    More actions

    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
    
  14. JacobEFO commented on Jun 26, 2024

    @JacobEFO
    JacobEFO
    on Jun 26, 2024
    Author
    More actions

    Thanks for following up. However, I seem to have no luck at all still.

    Where did you add the WSGIPAssAuthorization On flag?

  15. SchrodingersGat
    closed this as completedon Jul 3, 2024
  16. 9 remaining items

  17. SchrodingersGat commented on Sep 10, 2024

    @SchrodingersGat
    SchrodingersGat
    on Sep 10, 2024
    Member
    More actions

    @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#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)...

  18. anotherstevest2 commented on Mar 26, 2025

    @anotherstevest2
    anotherstevest2
    on Mar 26, 2025
    More actions

    @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:

    e.g. INVENTREE_SITE_URL=http://192.168.120.10 (but use an actual valid IP for your machine)...

    without success. I also saw:

    Adds option to bypass strict HTTPS checks #243

    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.

  19. SchrodingersGat commented on Mar 26, 2025

    @SchrodingersGat
    SchrodingersGat
    on Mar 26, 2025
    Member
    More actions

    @anotherstevest2 to test the "bypass strict HTTPS" mode, initialize the API call like thus:

    api = InvneTreeAPI(host, username='my_username', password='my_password', strict=False)

    Hopefully that helps

  20. anotherstevest2 commented on Mar 27, 2025

    @anotherstevest2
    anotherstevest2
    on Mar 27, 2025
    More actions

    @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.

  21. SchrodingersGat commented on Mar 27, 2025

    @SchrodingersGat
    SchrodingersGat
    on Mar 27, 2025
    Member
    More actions

    @anotherstevest2 I just released 0.17.5 which includes this fix - #265

    Please update your inventree-python installation and LMK if the issue is addressed.

  22. anotherstevest2 commented on Mar 27, 2025

    @anotherstevest2
    anotherstevest2
    on Mar 27, 2025
    More actions

    @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
    `

  23. SchrodingersGat commented on Mar 27, 2025

    @SchrodingersGat
    SchrodingersGat
    on Mar 27, 2025
    Member
    More actions

    Can you please LMK what version of urllib3 you are running:

    pip show urllib3
  24. anotherstevest2 commented on Mar 28, 2025

    @anotherstevest2
    anotherstevest2
    on Mar 28, 2025
    More actions

    @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)

  25. anotherstevest2 commented on Mar 28, 2025

    @anotherstevest2
    anotherstevest2
    on Mar 28, 2025
    More actions

    P.S. My response time is about to slow way down as I've got some travel...

  26. SchrodingersGat commented on Mar 28, 2025

    @SchrodingersGat
    SchrodingersGat
    on Mar 28, 2025
    Member
    More actions

    Ok, try running pip install -U urllib3 - I am on v2.3.0

  27. anotherstevest2 commented on Mar 29, 2025

    @anotherstevest2
    anotherstevest2
    on Mar 29, 2025
    More actions

    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`

  28. anotherstevest2 commented on Apr 9, 2025

    @anotherstevest2
    anotherstevest2
    on Apr 9, 2025
    More actions

    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.

  29. SchrodingersGat commented on Apr 9, 2025

    @SchrodingersGat
    SchrodingersGat
    on Apr 9, 2025
    Member
    More actions

    @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

  30. smahm006 commented on Jun 14, 2026

    @smahm006
    smahm006
    on Jun 14, 2026
    More actions

    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:

    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

    127.0.0.1 inventree.localhost
    ::1 inventree.localhost
    

    To /etc/hosts and trying again.

    Not sure what the proper solution is but at least I got something working locally....

  31. Carabela-del-Cielo commented on Jul 27, 2026

    @Carabela-del-Cielo
    Carabela-del-Cielo
    on Jul 27, 2026
    More actions

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.