A runnable Amazon captcha solver in Python: it detects Amazon's "Enter the characters you see below" page, reads the captcha image and submits the answer using requests and the ImageToText task of the official CapMonster Cloud image captcha solver Python SDK. No browser is needed.
- Opens an Amazon URL with a
requests.Session; by default the captcha check pageamazon.com/errors/validateCaptcha. - Detects the captcha form and collects the image URL, hidden fields and the name of the answer input.
- Downloads the image in the same session and recognizes it with
ImageToTextRequest. - Sends the answer to
validateCaptchaand repeats up to three times if a new captcha appears.
- Python 3.9+
- A CapMonster Cloud API key (see Get an API key)
git clone https://github.com/CapMonsterCloud/python-amazon-captcha-solver.git
cd python-amazon-captcha-solver
pip install -r requirements.txt
export CAPMONSTER_API_KEY=your_key # Windows: set CAPMONSTER_API_KEY=your_key
python examples/solve_amazon_captcha.py
python examples/solve_amazon_captcha.py --url https://www.amazon.com/dp/B000000000 --attempts 5Tests (offline, with a saved captcha page):
pytest -q- Detect, then parse.
is_captcha_page()looks for thevalidateCaptchaform and thecaptchacharactersinput, so normal product pages pass through untouched.parse_captcha_page()uses only the standardhtml.parser. - Hidden fields are mandatory. The form carries
amznandamzn-rvalues that link the answer to this specific captcha. They are sent back together with the answer infield-keywords. - Same session for page and image. The image is downloaded with the cookies of the page request; a fresh request would get a different captcha.
- Clean the answer. Amazon uses Latin letters only, so
clean_answer()uppercases the result and drops spaces, digits and punctuation that OCR sometimes adds. - Retry loop. Amazon may show another captcha after a correct answer; the script checks the response page and repeats.
- The task takes a picture of the captcha and returns the recognized characters as text.
- Send only the captcha image itself. The SDK takes the raw image bytes and encodes them for you.
- Each captcha is solved separately: when Amazon shows a new image, download it again in the same session and send a new request.
| Symptom | Cause and fix |
|---|---|
no captcha on the page |
Amazon did not ask for a captcha in this session. Nothing to solve, the cookies can be reused. |
ValueError: Amazon captcha form not found |
Amazon showed a different page (sign-in, 503 dog page). Save the HTML and check which form it contains. |
captcha is still shown after all attempts |
The session looks automated: add realistic headers, slow down, keep cookies, or use a proxy you are permitted to use. |
| Answer looks right but is rejected | The image was downloaded outside the session or the hidden fields were dropped. Keep one Session for all requests. |
[ERROR_ZERO_BALANCE] / [ERROR_KEY_DOES_NOT_EXIST] |
Top up the balance or check the API key. |
This example needs a CapMonster Cloud account and API key. Register and get the key on the image captcha recognition page. There you will also find pricing and the API description. New users can ask support for a $0.10 test balance after registering.
Automated access to Amazon is governed by Amazon's Conditions of Use. Use this example only where you have permission, for example for monitoring your own listings, and never for unauthorized collection of data. Keep your API key private.
- Python SDK: CapMonster Cloud Python SDK
- Image captcha recognition with CapMonster Cloud: capmonster.cloud/en/image-to-text
Amazon is a trademark of Amazon.com, Inc. or its affiliates. CapMonster Cloud is not affiliated with or endorsed by Amazon.