supervisely 6.73.218__py3-none-any.whl → 6.73.219__py3-none-any.whl

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.

Potentially problematic release.


This version of supervisely might be problematic. Click here for more details.

supervisely/api/api.py CHANGED
@@ -287,6 +287,8 @@ class Api:
287
287
  api_server_address: str = None,
288
288
  check_instance_version: Union[bool, str] = False,
289
289
  ):
290
+ self.logger = external_logger or logger
291
+
290
292
  if server_address is None and token is None:
291
293
  server_address = os.environ.get(SERVER_ADDRESS, None)
292
294
  token = os.environ.get(API_TOKEN, None)
@@ -295,10 +297,7 @@ class Api:
295
297
  raise ValueError(
296
298
  "SERVER_ADDRESS env variable is undefined, https://developer.supervisely.com/getting-started/basics-of-authentication"
297
299
  )
298
- if token is None:
299
- raise ValueError(
300
- "API_TOKEN env variable is undefined, https://developer.supervisely.com/getting-started/basics-of-authentication"
301
- )
300
+
302
301
  self.server_address = Api.normalize_server_address(server_address)
303
302
 
304
303
  self._api_server_address = None
@@ -313,11 +312,10 @@ class Api:
313
312
  if retry_sleep_sec is None:
314
313
  retry_sleep_sec = int(os.getenv(SUPERVISELY_PUBLIC_API_RETRY_SLEEP_SEC, "1"))
315
314
 
316
- if len(token) != 128:
317
- raise ValueError("Invalid token {!r}: length != 128".format(token))
318
-
319
315
  self.token = token
320
- self.headers = {"x-api-key": token}
316
+ self.headers = {}
317
+ if token is not None:
318
+ self.headers["x-api-key"] = token
321
319
  self.task_id = os.getenv(SUPERVISELY_TASK_ID)
322
320
  if self.task_id is not None and ignore_task_id is False:
323
321
  self.headers["x-task-id"] = self.task_id
@@ -359,8 +357,6 @@ class Api:
359
357
  self.retry_count = retry_count
360
358
  self.retry_sleep_sec = retry_sleep_sec
361
359
 
362
- self.logger = external_logger or logger
363
-
364
360
  self._require_https_redirect_check = not self.server_address.startswith("https://")
365
361
 
366
362
  if check_instance_version:
@@ -652,6 +648,14 @@ class Api:
652
648
  Api._raise_for_status(response)
653
649
  return response
654
650
  except requests.RequestException as exc:
651
+ if (
652
+ isinstance(exc, requests.exceptions.HTTPError)
653
+ and response.status_code == 400
654
+ and self.token is None
655
+ ):
656
+ self.logger.warning(
657
+ "API_TOKEN env variable is undefined. See more: https://developer.supervisely.com/getting-started/basics-of-authentication"
658
+ )
655
659
  if raise_error:
656
660
  raise exc
657
661
  else:
@@ -715,6 +719,14 @@ class Api:
715
719
  Api._raise_for_status(response)
716
720
  return response
717
721
  except requests.RequestException as exc:
722
+ if (
723
+ isinstance(exc, requests.exceptions.HTTPError)
724
+ and response.status_code == 400
725
+ and self.token is None
726
+ ):
727
+ self.logger.warning(
728
+ "API_TOKEN env variable is undefined. See more: https://developer.supervisely.com/getting-started/basics-of-authentication"
729
+ )
718
730
  process_requests_exception(
719
731
  self.logger,
720
732
  exc,
@@ -807,10 +819,11 @@ class Api:
807
819
 
808
820
  def _check_https_redirect(self):
809
821
  if self._require_https_redirect_check is True:
810
- response = requests.get(self.server_address, allow_redirects=False)
811
- if (300 <= response.status_code < 400) or (
812
- response.headers.get("Location", "").startswith("https://")
813
- ):
822
+ try:
823
+ response = requests.get(
824
+ self.server_address.replace("http://", "https://"), allow_redirects=False
825
+ )
826
+ response.raise_for_status()
814
827
  self.server_address = self.server_address.replace("http://", "https://")
815
828
  msg = (
816
829
  "You're using HTTP server address while the server requires HTTPS. "
@@ -818,8 +831,8 @@ class Api:
818
831
  f"Consider updating your server address to {self.server_address}"
819
832
  )
820
833
  self.logger.warn(msg)
821
-
822
- self._require_https_redirect_check = False
834
+ finally:
835
+ self._require_https_redirect_check = False
823
836
 
824
837
  @classmethod
825
838
  def from_credentials(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.218
3
+ Version: 6.73.219
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -22,7 +22,7 @@ supervisely/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  supervisely/api/advanced_api.py,sha256=Nd5cCnHFWc3PSUrCtENxTGtDjS37_lCHXsgXvUI3Ti8,2054
23
23
  supervisely/api/agent_api.py,sha256=ShWAIlXcWXcyI9fqVuP5GZVCigCMJmjnvdGUfLspD6Y,8890
24
24
  supervisely/api/annotation_api.py,sha256=Eps-Jf10_SQFy7DjghUnyiM6DcVJBsamHDViRAXv2fg,51403
25
- supervisely/api/api.py,sha256=u2T0yOQ-tUnP3iIzFu8zEQb4t_EDrXQSKnaXHCvFDyg,36514
25
+ supervisely/api/api.py,sha256=iq5wS7j95dfktZwubT2J9rBBMl-GHy75PkOQtZcwl24,37099
26
26
  supervisely/api/app_api.py,sha256=zX3Iy16RuGwtcLZfMs3YfUFc93S9AVGb3W_eINeMjOs,66729
27
27
  supervisely/api/dataset_api.py,sha256=7iwAyz3pmzFG2i072gLdXjczfBGbyj-V_rRl7Tx-V30,37944
28
28
  supervisely/api/file_api.py,sha256=y8FkE-vx1382cbhNo_rTZs7SobrkxmYQAe79CpvStO4,54279
@@ -997,9 +997,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
997
997
  supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
998
998
  supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
999
999
  supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
1000
- supervisely-6.73.218.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1001
- supervisely-6.73.218.dist-info/METADATA,sha256=EnGwT_zAqgvOytZQYfG8Cc6sTL3MniXkWeNgG-TXZP4,33090
1002
- supervisely-6.73.218.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
1003
- supervisely-6.73.218.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1004
- supervisely-6.73.218.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1005
- supervisely-6.73.218.dist-info/RECORD,,
1000
+ supervisely-6.73.219.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1001
+ supervisely-6.73.219.dist-info/METADATA,sha256=-yzVg7FtlrUZjhE7a0hRmL6ZofE6G3rLY6pB1KVoJ5Q,33090
1002
+ supervisely-6.73.219.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
1003
+ supervisely-6.73.219.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1004
+ supervisely-6.73.219.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1005
+ supervisely-6.73.219.dist-info/RECORD,,