alexdlaird / amazon-orders

A CLI and library for interacting with Amazon order history
https://amazon-orders.readthedocs.io
MIT License
23 stars 9 forks source link

Handle SMS OTP when captchas fail #9

Closed kylehendricks closed 10 months ago

kylehendricks commented 10 months ago

Acknowledgements

Describe the Feature

When the captcha is failed enough times, Amazon will switch to doing an SMS OTP. This request is to add support for that.

Describe Alternative Solutions/Workarounds

No response

alexdlaird commented 10 months ago

How many times? The default in the script is to timeout after 10, but that can be changed.

There already is support for Amazon OTP via voice or SMS, so if it’s not working, we'll need data to understand why.

Try running with the debug flag on and attach any log output and HTML files produced. You can follow the instructions in troubleshooting docs to see how to enable debug mode and send log data to the console. Also include any stacktraces, if you're seeing an error.

kylehendricks commented 10 months ago

Ah, my bad. Yea, I'm not sure if it was too many failed attempts to solve the captcha or just some sort of follow-up OTP?

When I just ran the example script now, I didn't get a captcha pop-up, immediately got an OTP sent via SMS, and got this stack trace:

Traceback (most recent call last):
  File "/Users/kylehendricks/source/amazon-orders/test.py", line 5, in <module>
    amazon_session.login()
  File "/Users/kylehendricks/source/amazon-orders/venv/lib/python3.11/site-packages/amazonorders/session.py", line 231, in login
    self._captcha_1_submit()
  File "/Users/kylehendricks/source/amazon-orders/venv/lib/python3.11/site-packages/amazonorders/session.py", line 328, in _captcha_1_submit
    captcha_div.find("img", {"alt": "captcha"}).attrs["src"])
    ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'find'

html.zip

alexdlaird commented 10 months ago

Perfect, this should give me everything I need, and I see the difference of why it's failing through to Captcha when it's actually an OTP page.

Amazon has so many different versions of the same page they push through the auth flow, it's going to take some work and crowdsourcing before we find them all.

I'll let you know when I implement this and push a new version, shouldn't take too much work, might have time tonight.

alexdlaird commented 10 months ago

Give version 1.0.4 a try, this should work now.

kylehendricks commented 10 months ago

Confirmed working in 1.0.4. Thanks!