qmenta-core 4.1.dev712__tar.gz → 4.1.dev713__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qmenta-core
3
- Version: 4.1.dev712
3
+ Version: 4.1.dev713
4
4
  Summary: QMENTA core library to communicate with the QMENTA platform.
5
5
  License: Proprietary
6
6
  Author: QMENTA
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "qmenta-core"
3
- version = "4.1.dev712"
3
+ version = "4.1.dev713"
4
4
  description = "QMENTA core library to communicate with the QMENTA platform."
5
5
  license = "Proprietary"
6
6
  authors = ["QMENTA <dev@qmenta.com>"]
@@ -4,7 +4,7 @@ import os
4
4
  import requests
5
5
  from getpass import getpass
6
6
  from pathlib import Path
7
- from typing import Optional, Dict, Any
7
+ from typing import Optional, Dict
8
8
  from urllib.parse import urljoin, urlparse
9
9
 
10
10
  from xdg import xdg_data_home
@@ -149,7 +149,7 @@ class Auth:
149
149
  ------
150
150
  ConnectionError
151
151
  If there was a problem setting up the network connection with the
152
- platform.
152
+ platform and for 404 and 5xx response status code.
153
153
  InvalidResponseError
154
154
  If the platform returned an invalid response.
155
155
  InvalidLoginError
@@ -164,25 +164,33 @@ class Auth:
164
164
  url: str = urljoin(base_url, '/login')
165
165
 
166
166
  try:
167
- r: requests.Response = requests.post(
167
+ response: requests.Response = requests.post(
168
168
  url, data={
169
169
  'username': username, 'password': password,
170
170
  'code_2fa': code_2fa
171
171
  }
172
172
  )
173
+ # Raises an exception for 4xx and 5xx status codes
174
+ response.raise_for_status()
175
+ # Assuming the response contains JSON data
176
+ data: dict = response.json()
177
+ # Process the data here
178
+ except requests.exceptions.HTTPError as e:
179
+ if e.response.status_code == 404:
180
+ raise ConnectionError("API returned a 404 error: Not Found")
181
+ else:
182
+ raise ConnectionError("API returned an error:", e)
183
+ except InvalidResponseError as e:
184
+ raise InvalidResponseError("Invalid Response Error:", e)
173
185
  except requests.RequestException as e:
174
186
  raise ConnectionError(str(e))
187
+ except Exception as e:
188
+ raise Exception("An error occurred:", e)
175
189
 
176
190
  try:
177
- d: Dict[str, Any] = r.json()
178
- except ValueError:
179
- raise InvalidResponseError(
180
- f'Could not decode JSON for response {r}')
181
-
182
- try:
183
- if d["success"] != 1:
191
+ if data["success"] != 1:
184
192
  # Login was not successful
185
- if 'account_state' in d and d['account_state'] == '2fa_need':
193
+ if data.get("account_state", "") == '2fa_need':
186
194
  if ask_for_2fa_input:
187
195
  input_2fa = input("Please enter your 2FA code: ")
188
196
  return Auth.login(
@@ -195,9 +203,9 @@ class Auth:
195
203
  'or set the ask_for_2fa_input parameter'
196
204
  )
197
205
  else:
198
- raise InvalidLoginError(d['error'])
206
+ raise InvalidLoginError(data['error'])
199
207
 
200
- token: str = d['token']
208
+ token: str = data['token']
201
209
  except KeyError as e:
202
210
  raise InvalidResponseError(f'Missing key: {e}')
203
211