aioamazondevices 3.0.7__tar.gz → 3.0.9__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: aioamazondevices
3
- Version: 3.0.7
3
+ Version: 3.0.9
4
4
  Summary: Python library to control Amazon devices
5
5
  License: Apache-2.0
6
6
  Author: Simone Chemelli
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aioamazondevices"
3
- version = "3.0.7"
3
+ version = "3.0.9"
4
4
  description = "Python library to control Amazon devices"
5
5
  authors = ["Simone Chemelli <simone.chemelli@gmail.com>"]
6
6
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  """aioamazondevices library."""
2
2
 
3
- __version__ = "3.0.7"
3
+ __version__ = "3.0.9"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
@@ -45,7 +45,12 @@ from .const import (
45
45
  SAVE_PATH,
46
46
  URI_QUERIES,
47
47
  )
48
- from .exceptions import CannotAuthenticate, CannotRegisterDevice, WrongMethod
48
+ from .exceptions import (
49
+ CannotAuthenticate,
50
+ CannotRegisterDevice,
51
+ RequestFailed,
52
+ WrongMethod,
53
+ )
49
54
 
50
55
 
51
56
  @dataclass
@@ -267,6 +272,14 @@ class AmazonEchoApi:
267
272
  _LOGGER.debug("Cookies from headers: %s", cookies_with_value)
268
273
  return cookies_with_value
269
274
 
275
+ async def _ignore_ap_sigin_error(self, response: ClientResponse) -> bool:
276
+ """Return true if error is due to /ap/sigin endpoint."""
277
+ # Endpoint 'ap/sigin' replies with error 404
278
+ # but reports the needed parameters anyway
279
+ return (
280
+ response.status == HTTPStatus.NOT_FOUND and "/ap/sigin" in response.url.name
281
+ )
282
+
270
283
  async def _session_request(
271
284
  self,
272
285
  method: str,
@@ -290,7 +303,7 @@ class AmazonEchoApi:
290
303
  headers.update(csrf)
291
304
 
292
305
  if json_data:
293
- json_header = {"Content-Type": "application/json"}
306
+ json_header = {"Content-Type": "application/json; charset=utf-8"}
294
307
  _LOGGER.debug("Adding %s to headers", json_header)
295
308
  headers.update(json_header)
296
309
 
@@ -314,6 +327,16 @@ class AmazonEchoApi:
314
327
  content_type,
315
328
  )
316
329
 
330
+ if resp.status != HTTPStatus.OK:
331
+ if resp.status in [
332
+ HTTPStatus.FORBIDDEN,
333
+ HTTPStatus.PROXY_AUTHENTICATION_REQUIRED,
334
+ HTTPStatus.UNAUTHORIZED,
335
+ ]:
336
+ raise CannotAuthenticate
337
+ if not self._ignore_ap_sigin_error(resp):
338
+ raise RequestFailed
339
+
317
340
  await self._save_to_file(
318
341
  await resp.text(),
319
342
  url,
@@ -20,7 +20,6 @@ DOMAIN_BY_ISO3166_COUNTRY = {
20
20
  },
21
21
  "jp": {
22
22
  "domain": "co.jp",
23
- "openid.assoc_handle": "jpflex",
24
23
  },
25
24
  "br": {
26
25
  "domain": "com.br",
@@ -41,8 +40,9 @@ DEFAULT_HEADERS = {
41
40
  f"Mozilla/5.0 (iPhone; CPU iPhone OS {AMAZON_CLIENT_OS.replace('.', '_')} like Mac OS X) " # noqa: E501
42
41
  "AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
43
42
  ),
44
- "Accept-Language": "en-US",
43
+ "Accept-Charset": "utf-8",
45
44
  "Accept-Encoding": "gzip",
45
+ "Accept-Language": "en-US",
46
46
  "Connection": "keep-alive",
47
47
  }
48
48
  CSRF_COOKIE = "csrf"
@@ -23,6 +23,10 @@ class CannotRegisterDevice(AmazonError):
23
23
  """Exception raised when device registration fails."""
24
24
 
25
25
 
26
+ class RequestFailed(AmazonError):
27
+ """Exception raised when a request fails."""
28
+
29
+
26
30
  class WrongMethod(AmazonError):
27
31
  """Exception raised when the wrong login metho is used."""
28
32