Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion inventree/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ def requestToken(self):
return False

# Request an auth token from the server
if self.api_version < 490:
token_url = 'user/token/'
else:
token_url = 'user/me/token/'
try:
response = self.get(
'user/token/',
token_url,
params={
'name': self.token_name,
}
Expand Down
15 changes: 13 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ def check_server(c, host="http://localhost:12345", username="testuser", password

auth = HTTPBasicAuth(username=username, password=password)

url = f"{host}/api/user/token/"
token_url = f"{host}/api/user/me/token/"
token_fallback_checked = False

response = None

while response is None:

try:
response = requests.get(url, auth=auth, timeout=0.5)
response = requests.get(token_url, auth=auth, timeout=0.5)
except Exception as e:
if debug:
print("Error:", str(e))
Expand All @@ -88,6 +89,16 @@ def check_server(c, host="http://localhost:12345", username="testuser", password
else:
return False

# Maybe this is an old implementation? Check for X-InvenTree-API header
if response and not token_fallback_checked:
token_version = response.headers.get('X-InvenTree-API', None)
if token_version and int(token_version) < 490:
if debug:
print("No token endpoint, but server is responding - maybe an old implementation?")
token_fallback_checked = True
token_url = f"{host}/api/user/token/"
response = None

if response.status_code != 200:
if debug:
print(f"Invalid status code: ${response.status_code}")
Expand Down
Loading