aioamazondevices 3.4.0__py3-none-any.whl → 3.5.1__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.
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "3.4.0"
3
+ __version__ = "3.5.1"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
aioamazondevices/api.py CHANGED
@@ -1,5 +1,6 @@
1
1
  """Support for Amazon devices."""
2
2
 
3
+ import asyncio
3
4
  import base64
4
5
  import hashlib
5
6
  import mimetypes
@@ -128,19 +129,19 @@ class AmazonEchoApi:
128
129
  # Force country digits as lower case
129
130
  country_code = login_country_code.lower()
130
131
 
131
- locale = DOMAIN_BY_ISO3166_COUNTRY.get(country_code)
132
- domain = locale["domain"] if locale else country_code
132
+ locale = DOMAIN_BY_ISO3166_COUNTRY.get(country_code, {})
133
+ domain = locale.get("domain", country_code)
134
+ market = locale.get("market", f"https://www.amazon.{domain}")
135
+ assoc_handle = locale.get(
136
+ "openid.assoc_handle", f"{DEFAULT_ASSOC_HANDLE}_{country_code}"
137
+ )
133
138
 
134
- if locale and (assoc := locale.get("openid.assoc_handle")):
135
- assoc_handle = assoc
136
- else:
137
- assoc_handle = f"{DEFAULT_ASSOC_HANDLE}_{country_code}"
138
139
  self._assoc_handle = assoc_handle
139
-
140
140
  self._login_email = login_email
141
141
  self._login_password = login_password
142
142
  self._login_country_code = country_code
143
143
  self._domain = domain
144
+ self._market = market
144
145
  self._cookies = self._build_init_cookies()
145
146
  self._csrf_cookie: str | None = None
146
147
  self._save_raw_data = save_raw_data
@@ -157,9 +158,10 @@ class AmazonEchoApi:
157
158
  self._language = f"{lang_maximized.language}-{lang_maximized.region}"
158
159
 
159
160
  _LOGGER.debug(
160
- "Initialize library with domain <%s> and language <%s>",
161
+ "Initialize library: domain <amazon.%s>, language <%s>, market: <%s>",
161
162
  self._domain,
162
163
  self._language,
164
+ self._market,
163
165
  )
164
166
 
165
167
  def _load_website_cookies(self) -> dict[str, str]:
@@ -369,15 +371,39 @@ class AmazonEchoApi:
369
371
  self._load_website_cookies() if self._login_stored_data else self._cookies
370
372
  )
371
373
  self.session.cookie_jar.update_cookies(_cookies)
372
- try:
373
- resp = await self.session.request(
374
- method,
375
- URL(url, encoded=True),
376
- data=input_data if not json_data else orjson.dumps(input_data),
377
- headers=headers,
378
- )
379
- except (TimeoutError, ClientConnectorError) as exc:
380
- raise CannotConnect(f"Connection error during {method}") from exc
374
+
375
+ resp: ClientResponse | None = None
376
+ for delay in [0, 1, 2, 5, 8, 12, 21]:
377
+ if delay:
378
+ _LOGGER.info(
379
+ "Sleeping for %s seconds before retrying API call to %s", delay, url
380
+ )
381
+ await asyncio.sleep(delay)
382
+
383
+ try:
384
+ resp = await self.session.request(
385
+ method,
386
+ URL(url, encoded=True),
387
+ data=input_data if not json_data else orjson.dumps(input_data),
388
+ headers=headers,
389
+ )
390
+
391
+ except (TimeoutError, ClientConnectorError) as exc:
392
+ _LOGGER.warning("Connection error to %s: %s", url, repr(exc))
393
+ raise CannotConnect(f"Connection error during {method}") from exc
394
+
395
+ # Retry with a delay only for specific HTTP status
396
+ # that can benefits of a back-off
397
+ if resp.status not in [
398
+ HTTPStatus.INTERNAL_SERVER_ERROR,
399
+ HTTPStatus.SERVICE_UNAVAILABLE,
400
+ HTTPStatus.TOO_MANY_REQUESTS,
401
+ ]:
402
+ break
403
+
404
+ if resp is None:
405
+ _LOGGER.error("No response received from %s", url)
406
+ raise CannotConnect(f"No response received from {url}")
381
407
 
382
408
  if not self._csrf_cookie:
383
409
  self._csrf_cookie = resp.cookies.get(CSRF_COOKIE, Morsel()).value
@@ -559,16 +585,14 @@ class AmazonEchoApi:
559
585
  raise CannotAuthenticate
560
586
 
561
587
  resp_me_json = await resp_me.json()
562
- market = resp_me_json["marketPlaceDomainName"]
563
-
564
- _domain = f"https://www.amazon.{self._domain}"
588
+ amazon_market = resp_me_json["marketPlaceDomainName"]
565
589
 
566
- if market != _domain:
590
+ if amazon_market != self._market:
567
591
  _LOGGER.warning(
568
592
  "Selected country <%s> doesn't matches Amazon API reply:\n%s\n vs \n%s",
569
593
  self._login_country_code.upper(),
570
- {"site ": _domain},
571
- {"market": market},
594
+ {"input ": self._market},
595
+ {"amazon": amazon_market},
572
596
  )
573
597
  raise WrongCountry
574
598
 
aioamazondevices/const.py CHANGED
@@ -49,9 +49,7 @@ DOMAIN_BY_ISO3166_COUNTRY = {
49
49
  "be": {
50
50
  "domain": "com.be",
51
51
  },
52
- "br": {
53
- "domain": "com.br",
54
- },
52
+ "br": AMAZON_US_OVERRIDE | {"market": "https://www.amazon.com.br"},
55
53
  "gb": {
56
54
  "domain": "co.uk",
57
55
  "openid.assoc_handle": f"{DEFAULT_ASSOC_HANDLE}_uk",
@@ -63,6 +61,10 @@ DOMAIN_BY_ISO3166_COUNTRY = {
63
61
  "mx": {
64
62
  "domain": "com.mx",
65
63
  },
64
+ "nl": {
65
+ "domain": "nl",
66
+ "market": "https://www.amazon.co.uk",
67
+ },
66
68
  "no": AMAZON_DE_OVERRIDE,
67
69
  "nz": {
68
70
  "domain": "com.au",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aioamazondevices
3
- Version: 3.4.0
3
+ Version: 3.5.1
4
4
  Summary: Python library to control Amazon devices
5
5
  License: Apache-2.0
6
6
  Author: Simone Chemelli
@@ -0,0 +1,11 @@
1
+ aioamazondevices/__init__.py,sha256=T7EODwcUnfDoPVfBfmfht_5uiC_fNyf1qm4chgXqIY4,276
2
+ aioamazondevices/api.py,sha256=kFdkvBHlGI1OITnRt1j8eASdVOzPLuftSF4U5jb6j28,40686
3
+ aioamazondevices/const.py,sha256=mQT0FAGqVtWsN6W93EzzwjqrMf7x8OT02TXdUCpKFus,9143
4
+ aioamazondevices/exceptions.py,sha256=CfOFKDvE_yl5BFoFcpTOuDfgRi_2oAtKk-nNJgfWBAs,726
5
+ aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
7
+ aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
8
+ aioamazondevices-3.5.1.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
9
+ aioamazondevices-3.5.1.dist-info/METADATA,sha256=IsrgAsKKym47Tmp7AkEipP5DCBEI_3pahiESCPe0HRw,6929
10
+ aioamazondevices-3.5.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ aioamazondevices-3.5.1.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- aioamazondevices/__init__.py,sha256=fd2mZWF9xVsM18tJqrX5LEGz06hXrnlPjWauYq6xMwA,276
2
- aioamazondevices/api.py,sha256=SBucwyavOv8aiXyw3iorZUA0qgA2cavCIzfdRanrbSQ,39733
3
- aioamazondevices/const.py,sha256=qeaGMLGKH4r-84EjBvMzj1BcwgRRcDD551TUsUu4AiI,9029
4
- aioamazondevices/exceptions.py,sha256=CfOFKDvE_yl5BFoFcpTOuDfgRi_2oAtKk-nNJgfWBAs,726
5
- aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
7
- aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
8
- aioamazondevices-3.4.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
9
- aioamazondevices-3.4.0.dist-info/METADATA,sha256=c61BBAOhX4xnSIsl2kMwqIQFbqo6abWYePtU0kCeZ1c,6929
10
- aioamazondevices-3.4.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
- aioamazondevices-3.4.0.dist-info/RECORD,,