aas-http-client 0.4.5__py3-none-any.whl → 0.4.7__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 aas-http-client might be problematic. Click here for more details.

aas_http_client/client.py CHANGED
@@ -62,7 +62,8 @@ def log_response_errors(response: Response): # noqa: C901
62
62
  result_error_messages.append(response.text)
63
63
 
64
64
  except json.JSONDecodeError:
65
- result_error_messages.append(response.content)
65
+ if response.content and response.content != "b''":
66
+ result_error_messages.append(response.content)
66
67
 
67
68
  logger.error(f"Status code: {response.status_code}")
68
69
  for result_error_message in result_error_messages:
@@ -729,14 +730,7 @@ def get_token_by_basic_auth(endpoint: str, username: str, password: str, timeout
729
730
 
730
731
  auth = HTTPBasicAuth(username, password)
731
732
 
732
- try:
733
- response = requests.post(endpoint, auth=auth, data=data, timeout=timeout)
734
- logger.info(f"Request URL: {response.url}")
735
- response.raise_for_status()
736
- return response.json().get("access_token")
737
- except requests.RequestException as e:
738
- logger.error(f"Error getting token: {e}")
739
- return None
733
+ return _get_token(endpoint, data, auth, timeout)
740
734
 
741
735
 
742
736
  def get_token_by_password(endpoint: str, username: str, password: str, timeout=200) -> dict | None:
@@ -750,10 +744,10 @@ def get_token_by_password(endpoint: str, username: str, password: str, timeout=2
750
744
  """
751
745
  data = {"grant_type": "password", "username": username, "password": password}
752
746
 
753
- return _get_token(endpoint, data, timeout)
747
+ return _get_token(endpoint, data, None, timeout)
754
748
 
755
749
 
756
- def _get_token(endpoint: str, data: dict[str, str], timeout: int = 200) -> dict | None:
750
+ def _get_token(endpoint: str, data: dict[str, str], auth: HTTPBasicAuth | None = None, timeout: int = 200) -> dict | None:
757
751
  """Get token from a specific authentication service provider.
758
752
 
759
753
  :param endpoint: Get token endpoint for the authentication service provider
@@ -762,13 +756,20 @@ def _get_token(endpoint: str, data: dict[str, str], timeout: int = 200) -> dict
762
756
  :return: Access token or None if an error occurred
763
757
  """
764
758
  try:
765
- response = requests.post(endpoint, json=data, timeout=timeout)
766
- logger.info(f"Request URL: {response.url}")
767
- response.raise_for_status()
768
- return response.json().get("access_token")
769
- except requests.RequestException as e:
770
- logger.error(f"Error getting token: {e}")
771
- return None
759
+ response = requests.post(endpoint, auth=auth, data=data, timeout=timeout)
760
+ logger.debug(f"Call REST API url '{response.url}'")
761
+
762
+ if response.status_code != STATUS_CODE_200:
763
+ log_response_errors(response)
764
+ return None
765
+
766
+ except requests.exceptions.RequestException as e:
767
+ logger.error(f"Error call REST API: {e}")
768
+ return False
769
+
770
+ content = response.content.decode("utf-8")
771
+ data = json.loads(content)
772
+ return data.get("access_token", None)
772
773
 
773
774
 
774
775
  def create_client_by_url(
@@ -39,9 +39,15 @@ def create_base_submodel_element_property(
39
39
  return sme
40
40
 
41
41
 
42
- def clone_submodel_element_property(property: model.Property) -> model.Property:
43
- """Clone a SubmodelElement of type Property."""
44
- sme = model.Property(id_short=property.id_short, value_type=property.value_type, value=property.value)
42
+ def clone_submodel_element_property(property: model.Property, new_id_short: str) -> model.Property:
43
+ """Clones a given property.
44
+
45
+ :param property: Given property to clone
46
+ :param new_id_short: New ID short for the cloned property.
47
+ :return: Cloned property
48
+ """
49
+ sme = model.Property(id_short=new_id_short, value_type=property.value_type, value=property.value)
50
+
45
51
  sme.description = property.description
46
52
  sme.display_name = property.display_name
47
53
  sme.value = property.value
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.4.5
3
+ Version: 0.4.7
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -1,16 +1,16 @@
1
1
  aas_http_client/__init__.py,sha256=bBfrdXUHvukisXIj0CcnNUHUw8_7nrdnfQRve8nM_3U,982
2
- aas_http_client/client.py,sha256=nanCcuT3dKYN-mH8QFlu0Huz_YxPTz6lnRUYvhGHCvw,35453
2
+ aas_http_client/client.py,sha256=1FXkYzyHQQVBKzx0lzfYJVATyrezbeb1xZChErfPCKQ,35452
3
3
  aas_http_client/classes/auth_classes.py,sha256=us1oDlBpI7R3xp2pcr9ZJ_AAaM65J-g8neq-d1M2FHw,619
4
4
  aas_http_client/core/encoder.py,sha256=FS7P0FPakzFsGz70eRFDHQZFA_2nlKLlWIxavtnFrPg,660
5
5
  aas_http_client/core/version_check.py,sha256=9dR0Q6jCFygH_ctj4vyrjerpHvolT87ayengZFlBWCw,708
6
6
  aas_http_client/demo/demo_process.py,sha256=uCyvotKWRItlhjNX7ek7ek3r5gXZ3jSARvvzcKhzyqw,3971
7
7
  aas_http_client/demo/logging_handler.py,sha256=VJtZ4u3x_LhYZQtfNck7FuXhGFZm7gid0uDhvf9GjJ8,5596
8
8
  aas_http_client/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- aas_http_client/utilities/model_builder.py,sha256=SxAv8DJkKksykw_2gtTV2jHu-MRzevOVzspn807_7VA,4680
9
+ aas_http_client/utilities/model_builder.py,sha256=l-Y8p5SLFwCWvSqukO_pF5Ncv5_oZ3MGoKgVrqkVwPw,4821
10
10
  aas_http_client/utilities/sdk_tools.py,sha256=CDD0mus8jOi-irgPO6dQHulmEyu8BSG_05Mol_nirK0,2008
11
11
  aas_http_client/wrapper/sdk_wrapper.py,sha256=OneN_9rtFSYUjnQWFcQneg8cih5YhkyLER4NZTAgUR0,16443
12
- aas_http_client-0.4.5.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
13
- aas_http_client-0.4.5.dist-info/METADATA,sha256=oqndOuniDMjxkEvJgBpmyvgyCmbFtJxvACEzqFV3msQ,10467
14
- aas_http_client-0.4.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- aas_http_client-0.4.5.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
16
- aas_http_client-0.4.5.dist-info/RECORD,,
12
+ aas_http_client-0.4.7.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
13
+ aas_http_client-0.4.7.dist-info/METADATA,sha256=dP54xG69lpc5D-OhzXvDuU_zlg27GFWm_fzGLfhXFQA,10467
14
+ aas_http_client-0.4.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ aas_http_client-0.4.7.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
16
+ aas_http_client-0.4.7.dist-info/RECORD,,