-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
When trying to use this API with a server running a self signed certificate, the strict=False is ignored in the InvenTreeAPI.testServer method. This causes API calls to fail.
Changing this line:
inventree-python/inventree/api.py
Line 199 in ae1f228
| response = requests.get(self.api_url, timeout=self.timeout, proxies=self.proxies) |
to:
response = requests.get(self.api_url, timeout=self.timeout, proxies=self.proxies, verify=self.strict)fixes the issue.
Environment
.inventree_venv/bin/pip freeze
certifi==2025.1.31
charset-normalizer==3.4.1
idna==3.10
inventree==0.17.3
requests==2.32.3
urllib3==2.3.0
api_test.py
import logging
from inventree.part import Part
from inventree.api import InvenTreeAPI
fmt = "%(asctime)-15s %(process)-8d %(levelname)-7s %(name)s %(filename)s:%(funcName)s:%(lineno)d - %(message)s"
logging.basicConfig(level=logging.DEBUG, format=fmt)
SERVER_ADDRESS = 'https://localhost:8443'
MY_USERNAME = 'not_my_real_username'
MY_PASSWORD = 'not_my_real_password'
api = InvenTreeAPI(SERVER_ADDRESS, username=MY_USERNAME, password=MY_PASSWORD, strict=False)
parts = Part.list(api, category=10, assembly=True)Current Behavior
2025-02-05 10:20:35,993 643504 INFO inventree api.py:connect:116 - Connecting to server: https://localhost:8443/
2025-02-05 10:20:35,993 643504 INFO inventree api.py:testServer:196 - Checking InvenTree server connection...
2025-02-05 10:20:35,994 643504 DEBUG urllib3.connectionpool connectionpool.py:_new_conn:1053 - Starting new HTTPS connection (1): localhost:8443
2025-02-05 10:20:36,002 643504 CRITICAL inventree api.py:testServer:202 - Server connection error: <class 'requests.exceptions.SSLError'>
2025-02-05 10:20:36,002 643504 INFO inventree api.py:testAuth:165 - Checking InvenTree user credentials
2025-02-05 10:20:36,002 643504 CRITICAL inventree api.py:testAuth:168 - InvenTree server is not connected. Skipping authentication check
Traceback (most recent call last):
File "api_test.py", line 26, in <module>
main()
File "api_test.py", line 20, in main
api = InvenTreeAPI(SERVER_ADDRESS, username=MY_USERNAME, password=MY_PASSWORD, strict=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/inventree/api.py", line 79, in __init__
self.connect()
File ".venv/lib/python3.12/site-packages/inventree/api.py", line 133, in connect
raise ConnectionError("Authentication at InvenTree server failed")
ConnectionError: Authentication at InvenTree server failed
Expected Behavior
2025-02-05 10:31:47,340 645470 INFO inventree api.py:connect:116 - Connecting to server: https://localhost:8443/
2025-02-05 10:31:47,341 645470 INFO inventree api.py:testServer:196 - Checking InvenTree server connection...
2025-02-05 10:31:47,341 645470 DEBUG urllib3.connectionpool connectionpool.py:_new_conn:1053 - Starting new HTTPS connection (1): localhost:8443
.venv/lib/python3.12/site-packages/urllib3/connectionpool.py:1100: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
2025-02-05 10:31:47,437 645470 DEBUG urllib3.connectionpool connectionpool.py:_make_request:547 - https://localhost:8443 "GET /api/ HTTP/1.1" 200 1252
2025-02-05 10:31:47,438 645470 INFO inventree api.py:testServer:214 - InvenTree server details: {"server": "InvenTree", "version": "0.17.5", "instance": "InvenTree", "apiVersion": 294, "worker_running": true, "worker_count": 4, "worker_pending_tasks": 0, "plugins_enabled": true, "plugins_install_disabled": false, "active_plugins": [{"name": "InvenTreeBarcode", "slug": "inventreebarcode", "version": "2.1.0"}, {"name": "InvenTreeCoreNotificationsPlugin", "slug": "inventreecorenotificationsplugin", "version": "1.0.0"}, {"name": "InvenTreeCurrencyExchange", "slug": "inventreecurrencyexchange", "version": "1.0.0"}, {"name": "InvenTreeLabel", "slug": "inventreelabel", "version": "1.1.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"}], "email_configured": false, "debug_mode": false, "docker_mode": true, "default_locale": "en-us", "system_health": null, "database": null, "platform": null, "installer": null, "target": null, "django_admin": null}
2025-02-05 10:31:47,439 645470 INFO inventree api.py:testAuth:165 - Checking InvenTree user credentials
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:335 - Sending Request:
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:336 - - URL: GET https://localhost:8443/api/user/me/
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:339 - - params: {}
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:339 - - timeout: 10
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:339 - - headers: {}
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:339 - - auth: <requests.auth.HTTPBasicAuth object at 0x7bac413985c0>
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:339 - - proxies: {}
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:339 - - json: {}
2025-02-05 10:31:47,440 645470 DEBUG inventree api.py:request:339 - - verify: False
2025-02-05 10:31:47,441 645470 DEBUG urllib3.connectionpool connectionpool.py:_new_conn:1053 - Starting new HTTPS connection (1): localhost:8443
.venv/lib/python3.12/site-packages/urllib3/connectionpool.py:1100: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
2025-02-05 10:31:48,422 645470 DEBUG urllib3.connectionpool connectionpool.py:_make_request:547 - https://localhost:8443 "GET /api/user/me/ HTTP/1.1" 200 135
2025-02-05 10:31:48,423 645470 INFO inventree api.py:request:357 - Request: GET https://localhost:8443/api/user/me/ - 200
2025-02-05 10:31:48,424 645470 INFO inventree api.py:requestToken:243 - Requesting auth token from server...
2025-02-05 10:31:48,425 645470 DEBUG inventree api.py:request:335 - Sending Request:
2025-02-05 10:31:48,425 645470 DEBUG inventree api.py:request:336 - - URL: GET https://localhost:8443/api/user/token/
2025-02-05 10:31:48,425 645470 DEBUG inventree api.py:request:339 - - params: {'name': 'inventree-python-client'}
2025-02-05 10:31:48,425 645470 DEBUG inventree api.py:request:339 - - timeout: 10
2025-02-05 10:31:48,425 645470 DEBUG inventree api.py:request:339 - - headers: {}
2025-02-05 10:31:48,425 645470 DEBUG inventree api.py:request:339 - - auth: <requests.auth.HTTPBasicAuth object at 0x7bac413985c0>
2025-02-05 10:31:48,426 645470 DEBUG inventree api.py:request:339 - - proxies: {}
2025-02-05 10:31:48,426 645470 DEBUG inventree api.py:request:339 - - json: {}
2025-02-05 10:31:48,426 645470 DEBUG inventree api.py:request:339 - - verify: False
2025-02-05 10:31:48,427 645470 DEBUG urllib3.connectionpool connectionpool.py:_new_conn:1053 - Starting new HTTPS connection (1): localhost:8443
.venv/lib/python3.12/site-packages/urllib3/connectionpool.py:1100: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
2025-02-05 10:31:49,490 645470 DEBUG urllib3.connectionpool connectionpool.py:_make_request:547 - https://localhost:8443 "GET /api/user/token/?name=inventree-python-client HTTP/1.1" 200 120
2025-02-05 10:31:49,492 645470 INFO inventree api.py:request:357 - Request: GET https://localhost:8443/api/user/token/ - 200
2025-02-05 10:31:49,493 645470 INFO inventree api.py:requestToken:267 - Authentication token: <GENERATED_TOKEN>
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:335 - Sending Request:
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:336 - - URL: GET https://localhost:8443/api/part/
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:339 - - params: {'category': 10, 'assembly': True}
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:339 - - timeout: 10
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:339 - - headers: {'AUTHORIZATION': 'Token <GENERATED_TOKEN>'}
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:339 - - auth: None
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:339 - - proxies: {}
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:339 - - json: {}
2025-02-05 10:31:49,494 645470 DEBUG inventree api.py:request:339 - - verify: False
2025-02-05 10:31:49,495 645470 DEBUG urllib3.connectionpool connectionpool.py:_new_conn:1053 - Starting new HTTPS connection (1): localhost:8443
.venv/lib/python3.12/site-packages/urllib3/connectionpool.py:1100: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
2025-02-05 10:31:49,697 645470 DEBUG urllib3.connectionpool connectionpool.py:_make_request:547 - https://localhost:8443 "GET /api/part/?category=10&assembly=True HTTP/1.1" 200 2
2025-02-05 10:31:49,697 645470 INFO inventree api.py:request:357 - Request: GET https://localhost:8443/api/part/ - 200
Metadata
Metadata
Assignees
Labels
No labels