chemelli74 / aioamazondevices

Python library to control Amazon devices
Apache License 2.0
17 stars 2 forks source link

Amazon-JP "GET request" URL request parameters Error #57

Open collelog opened 3 days ago

collelog commented 3 days ago

For Amazon-JP, the request parameter “openid.asset_handle=amzn_dp_project_dee_ios” needs to be replaced with “openid.asset_handle=jpflex”.

1. Execution result before program modification

> python3 library_test.py -c jp -e test@test -p test OTP Code: 0

Traceback (most recent call last):
  File "/root/mypy/library_test.py", line 143, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/root/mypy/library_test.py", line 82, in main
    login_data = await api.login(args.otp_code or input("OTP Code: "))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mypy/lib/python3.11/site-packages/aioamazondevices/api.py", line 339, in login
    login_method, login_url = self._get_request_from_soup(login_soup)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mypy/lib/python3.11/site-packages/aioamazondevices/api.py", line 163, in _get_request_from_soup
    method = form["method"]
             ~~~~^^^^^^^^^^
  File "/root/mypy/lib/python3.11/site-packages/bs4/element.py", line 1573, in __getitem__
    return self.attrs[key]
           ~~~~~~~~~~^^^^^
KeyError: 'method'

> cat example.log

DEBUG:aioamazondevices:Logging-in for test@test [otp code 0]
DEBUG:aioamazondevices:Creating HTTP ClientSession
DEBUG:aioamazondevices:Build oauth URL
DEBUG:aioamazondevices:GET request: https://www.amazon.co.jp/ap/signin?openid.oa2.response_type=code&openid.oa2.code_challenge_method=S256&openid.oa2.code_challenge=lR378lEnG4RiRAqYqGHPYXetl6aAeFYquYOCpFIl_fA&openid.return_to=https%3A%2F%2Fwww.amazon.co.jp%2Fap%2Fmaplanding&openid.assoc_handle=amzn_dp_project_dee_ios&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&accountStatusPolicy=P1&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns.oa2=http%3A%2F%2Fwww.amazon.com%2Fap%2Fext%2Foauth%2F2&openid.oa2.client_id=device%3A393030323042414335393030344341374133454338443339313646313536343123413249564c5635564d32573831&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.oa2.scope=device_auth_access&forceMobileLayout=true&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.pape.max_auth_age=0 with payload None
DEBUG:aioamazondevices:Response content type: text/html;charset=UTF-8
DEBUG:aioamazondevices:Get request data from HTML source

0

2. Tentative modifications to the program

> diff /root/mypy/lib/python3.11/site-packages/aioamazondevices/api.py /root/mypy/lib/python3.11/site- packages/aioamazondevices/api.py.org

64c64
<         assoc_handle = "jpflex"
---
>         assoc_handle = "amzn_dp_project_dee_ios"

3. Execution result after program modification

> python3 library_test.py -c jp -e test@test -p test OTP Code: 0

Cannot authenticate with test@test credentials

> cat example.log

DEBUG:aioamazondevices:Logging-in for test@test [otp code 0]
DEBUG:aioamazondevices:Creating HTTP ClientSession
DEBUG:aioamazondevices:Build oauth URL
DEBUG:aioamazondevices:GET request: https://www.amazon.co.jp/ap/signin?openid.oa2.response_type=code&openid.oa2.code_challenge_method=S256&openid.oa2.code_challenge=7e9z3vaFqFhKoQIjKG4mTegE8qsTHD_3NFxMS4ymdFA&openid.return_to=https%3A%2F%2Fwww.amazon.co.jp%2Fap%2Fmaplanding&openid.assoc_handle=jpflex&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&accountStatusPolicy=P1&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns.oa2=http%3A%2F%2Fwww.amazon.com%2Fap%2Fext%2Foauth%2F2&openid.oa2.client_id=device%3A394243314644453638344238344443444142313145354241324337373146423423413249564c5635564d32573831&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.oa2.scope=device_auth_access&forceMobileLayout=true&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.pape.max_auth_age=0 with payload None
DEBUG:aioamazondevices:Response content type: text/html;charset=UTF-8
DEBUG:aioamazondevices:Get request data from HTML source
DEBUG:aioamazondevices:Register at https://www.amazon.co.jp/ap/signin/357-9746582-5382426

1

4. Test results by authorized account

> python3 library_test.py -c jp -e xxx@xxx.co.jp -p xxxxxxxxxx OTP Code: xxxxxx

Logged-in.
--------------------
Login data: {
  .....
}
--------------------
--------------------
Devices: {
  .....
}
--------------------
chemelli74 commented 3 days ago

Hi @collelog , thx so much for your work !

Will update code accordly in a while.

jeeftor commented 3 days ago

I think we're likely missing other zones TBH ... but we can patch them as they come in :)

chemelli74 commented 3 days ago

@collelog, please test linked PR and report back

collelog commented 2 days ago

Thank you for fixing the PG. The test results for the fixed PG were fine.

Test Case 1

python3 library_test.py -c us -e test@test -p test

OTP Code: 0
Cannot authenticate with test@test credentials

python3 library_test.py -c jp -e test@test -p test

OTP Code: 0
Cannot authenticate with test@test credentials

python3 library_test.py -c us -e test@test -p test

OTP Code: 0
Cannot authenticate with test@test credentials

python3 library_test.py -c uk -e test@test -p test

OTP Code: 0
Cannot authenticate with test@test credentials

python3 library_test.py -c au -e test@test -p test

OTP Code: 0
Cannot authenticate with test@test credentials

python3 library_test.py -c br -e test@test -p test

OTP Code: 0
Cannot authenticate with test@test credentials

Test Case 2

python3 library_test.py -c jp -e xxx@xxx.co.jp -p xxx

OTP Code: NNNNNN
Logged-in.
--------------------
Login data: {....}
--------------------
--------------------
Devices: {....}
--------------------