├── requirements.txt ├── examples ├── images │ ├── grid.jpg │ ├── canvas.jpg │ ├── grid_2.jpg │ ├── normal.jpg │ ├── rotate.jpg │ ├── grid_hint.jpg │ ├── normal_2.jpg │ └── canvas_hint.jpg ├── coordinates.py ├── normal.py ├── rotate.py ├── canvas.py ├── text.py ├── text_options.py ├── geetest_v4.py ├── normal_base64.py ├── coordinates_base64.py ├── recaptcha_v2.py ├── grid.py ├── canvas_base64.py ├── recaptcha_v3.py ├── rotate_options.py ├── funcaptcha.py ├── canvas_options.py ├── coordinates_options.py ├── grid_base64.py ├── keycaptcha.py ├── grid_options.py ├── normal_options.py ├── turnstile.py ├── geetest.py ├── funcaptcha_options.py ├── recaptcha_v3_options.py ├── geetest_options.py ├── recaptcha_v2_options.py ├── geetest_v4_options.py ├── keycaptcha_options.py └── turnstile_options.py ├── solvecaptcha ├── __init__.py ├── api.py └── solver.py ├── tests ├── test_geetest_v4.py ├── test_turnstile.py ├── test_text.py ├── test_geetest.py ├── test_keycaptcha.py ├── test_funcaptcha.py ├── test_coordinates.py ├── abstract.py ├── test_recaptcha.py ├── test_grid.py └── test_normal.py ├── .github └── workflows │ └── publish-to-pypi.yml ├── LICENSE ├── setup.py ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── README.md /requirements.txt: -------------------------------------------------------------------------------- 1 | requests>=2.20.0 -------------------------------------------------------------------------------- /examples/images/grid.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/grid.jpg -------------------------------------------------------------------------------- /examples/images/canvas.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/canvas.jpg -------------------------------------------------------------------------------- /examples/images/grid_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/grid_2.jpg -------------------------------------------------------------------------------- /examples/images/normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/normal.jpg -------------------------------------------------------------------------------- /examples/images/rotate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/rotate.jpg -------------------------------------------------------------------------------- /examples/images/grid_hint.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/grid_hint.jpg -------------------------------------------------------------------------------- /examples/images/normal_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/normal_2.jpg -------------------------------------------------------------------------------- /examples/images/canvas_hint.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solvercaptcha/solvecaptcha-python/HEAD/examples/images/canvas_hint.jpg -------------------------------------------------------------------------------- /solvecaptcha/__init__.py: -------------------------------------------------------------------------------- 1 | from .api import ApiClient 2 | from .solver import (Solvecaptcha, SolverExceptions, ValidationException, 3 | NetworkException, ApiException, TimeoutException) 4 | 5 | """ 6 | Python 3 package for easy integration with the API of solvecaptcha.com captcha solving service 7 | to bypass ReCaptcha, Funcaptcha, Geetest and solve any other captchas. 8 | 9 | Website: https://solvecaptcha.com/ 10 | Support: indo@solvecaptcha.com 11 | License: MIT 12 | """ 13 | 14 | __author__ = 'SolveCaptcha' 15 | __version__ = '1.0.2' 16 | -------------------------------------------------------------------------------- /examples/coordinates.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 4 | 5 | from solvecaptcha import Solvecaptcha 6 | 7 | # In this example, we store the API key in environment variables, which can be set as follows: 8 | # On Linux or macOS: 9 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 10 | # On Windows: 11 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # Alternatively, you can directly assign the API key to a variable: 13 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 14 | 15 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 16 | 17 | solver = Solvecaptcha(api_key) 18 | 19 | try: 20 | result = solver.coordinates('./images/grid.jpg') 21 | 22 | except Exception as e: 23 | sys.exit(e) 24 | 25 | else: 26 | sys.exit('result: ' + str(result)) 27 | -------------------------------------------------------------------------------- /examples/normal.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.normal('./images/normal.jpg') 22 | 23 | except Exception as e: 24 | sys.exit(e) 25 | 26 | else: 27 | sys.exit('result: ' + str(result)) 28 | -------------------------------------------------------------------------------- /examples/rotate.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.rotate('./images/rotate.jpg') 22 | 23 | except Exception as e: 24 | sys.exit(e) 25 | 26 | else: 27 | sys.exit('result: ' + str(result)) 28 | -------------------------------------------------------------------------------- /examples/canvas.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 4 | 5 | from solvecaptcha import Solvecaptcha 6 | 7 | # In this example, we store the API key in environment variables, which can be set as follows: 8 | # On Linux or macOS: 9 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 10 | # On Windows: 11 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # Alternatively, you can directly assign the API key to a variable: 13 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 14 | 15 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 16 | 17 | solver = Solvecaptcha(api_key) 18 | 19 | try: 20 | result = solver.canvas('./images/canvas.jpg', hintText='Draw around apple') 21 | 22 | except Exception as e: 23 | sys.exit(e) 24 | 25 | else: 26 | sys.exit('result: ' + str(result)) 27 | -------------------------------------------------------------------------------- /examples/text.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.text('If tomorrow is Saturday, what day is today?') 22 | 23 | except Exception as e: 24 | sys.exit(e) 25 | 26 | else: 27 | print(result) 28 | sys.exit('result: ' + str(result)) 29 | -------------------------------------------------------------------------------- /tests/test_geetest_v4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | try: 6 | from .abstract import AbstractTest 7 | except ImportError: 8 | from abstract import AbstractTest 9 | 10 | 11 | 12 | class GeeTest_V4(AbstractTest): 13 | 14 | 15 | def test_all_params(self): 16 | 17 | 18 | params = { 19 | 'captcha_id': 'e392e1d7fd421dc63325744d5a2b9c73', 20 | 'url' : 'https://mysite.com/page/with/geetest-v4', } 21 | 22 | sends = { 23 | 'method' : 'geetest_v4', 24 | 'captcha_id' : 'e392e1d7fd421dc63325744d5a2b9c73', 25 | 'pageurl' : 'https://mysite.com/page/with/geetest-v4', 26 | } 27 | 28 | return self.send_return(sends, self.solver.geetest_v4, **params) 29 | 30 | 31 | if __name__ == '__main__': 32 | 33 | unittest.main() 34 | 35 | -------------------------------------------------------------------------------- /examples/text_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key, defaultTimeout=50, pollingInterval=10) 19 | 20 | try: 21 | result = solver.text('If tomorrow is Saturday, what day is today?', 22 | lang='en') 23 | 24 | except Exception as e: 25 | sys.exit(e) 26 | 27 | else: 28 | sys.exit('result: ' + str(result)) 29 | -------------------------------------------------------------------------------- /.github/workflows/publish-to-pypi.yml: -------------------------------------------------------------------------------- 1 | name: Publish to PyPI 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*.*.*' # Workflow start when you push tag in folovings format: v1.0.0 7 | 8 | jobs: 9 | build-and-publish: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v3 14 | 15 | - name: Setup Python 16 | uses: actions/setup-python@v4 17 | with: 18 | python-version: '3.10' # Python version 19 | 20 | - name: Upgrade pip 21 | run: pip install --upgrade pip 22 | 23 | - name: Install build dependencies 24 | run: pip install build 25 | 26 | - name: Build the package 27 | run: python -m build --sdist --wheel 28 | 29 | - name: Publish to PyPI via Twine 30 | env: 31 | PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} 32 | run: | 33 | pip install twine 34 | twine upload dist/* -u __token__ -p $PYPI_API_TOKEN -------------------------------------------------------------------------------- /examples/geetest_v4.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import requests 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73', 22 | url='https://mysite.com/page/with//geetest-v4') 23 | 24 | except Exception as e: 25 | sys.exit(e) 26 | 27 | else: 28 | sys.exit('result: ' + str(result)) 29 | -------------------------------------------------------------------------------- /examples/normal_base64.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | from base64 import b64encode 4 | 5 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 6 | 7 | from solvecaptcha import Solvecaptcha 8 | 9 | # In this example, we store the API key in environment variables, which can be set as follows: 10 | # On Linux or macOS: 11 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # On Windows: 13 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 14 | # Alternatively, you can directly assign the API key to a variable: 15 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 16 | 17 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 18 | 19 | solver = Solvecaptcha(api_key) 20 | 21 | with open('./images/normal.jpg', 'rb') as f: 22 | b64 = b64encode(f.read()).decode('utf-8') 23 | 24 | try: 25 | result = solver.normal(b64) 26 | 27 | except Exception as e: 28 | sys.exit(e) 29 | 30 | else: 31 | sys.exit('result: ' + str(result)) 32 | -------------------------------------------------------------------------------- /examples/coordinates_base64.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | from base64 import b64encode 4 | 5 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 6 | 7 | from solvecaptcha import Solvecaptcha 8 | 9 | # In this example, we store the API key in environment variables, which can be set as follows: 10 | # On Linux or macOS: 11 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # On Windows: 13 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 14 | # Alternatively, you can directly assign the API key to a variable: 15 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 16 | 17 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 18 | 19 | solver = Solvecaptcha(api_key) 20 | 21 | with open('./images/grid.jpg', 'rb') as f: 22 | b64 = b64encode(f.read()).decode('utf-8') 23 | 24 | try: 25 | result = solver.coordinates(b64) 26 | 27 | except Exception as e: 28 | sys.exit(e) 29 | 30 | else: 31 | sys.exit('result: ' + str(result)) 32 | -------------------------------------------------------------------------------- /examples/recaptcha_v2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.recaptcha( 22 | sitekey='6LdO5_IbAAAAAAeVBL9TClS19NUTt5wswEb3Q7C5', 23 | url='https://mysite.com/page/with/recaptcha-v2' 24 | ) 25 | 26 | except Exception as e: 27 | sys.exit(e) 28 | 29 | else: 30 | sys.exit('result: ' + str(result)) 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/grid.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.grid('./images/grid_2.jpg', 22 | hintText='Select all images with an Orange', 23 | rows=3, 24 | cols=3) 25 | 26 | except Exception as e: 27 | sys.exit(e) 28 | 29 | else: 30 | sys.exit('result: ' + str(result)) 31 | -------------------------------------------------------------------------------- /tests/test_turnstile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | try: 6 | from .abstract import AbstractTest 7 | except ImportError: 8 | from abstract import AbstractTest 9 | 10 | class TurnstileTest(AbstractTest): 11 | 12 | 13 | def test_all_params(self): 14 | 15 | 16 | params = { 17 | 'sitekey' : '0x4AAAAAAAC3DHQFLr1GavRN', 18 | 'url' : 'https://www.site.com/page/', 19 | 'action' : 'foo', 20 | 'data' : 'bar' 21 | } 22 | 23 | sends = { 24 | 'method' : 'turnstile', 25 | 'sitekey' : '0x4AAAAAAAC3DHQFLr1GavRN', 26 | 'action' : 'foo', 27 | 'data' : 'bar', 28 | 'pageurl' : 'https://www.site.com/page/', 29 | } 30 | 31 | return self.send_return(sends, self.solver.turnstile, **params) 32 | 33 | 34 | if __name__ == '__main__': 35 | 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /examples/canvas_base64.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | from base64 import b64encode 4 | 5 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 6 | 7 | from solvecaptcha import Solvecaptcha 8 | 9 | # In this example, we store the API key in environment variables, which can be set as follows: 10 | # On Linux or macOS: 11 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # On Windows: 13 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 14 | # Alternatively, you can directly assign the API key to a variable: 15 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 16 | 17 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 18 | 19 | solver = Solvecaptcha(api_key) 20 | 21 | with open('./images/canvas.jpg', 'rb') as f: 22 | b64 = b64encode(f.read()).decode('utf-8') 23 | 24 | try: 25 | result = solver.canvas(b64, hintText='Draw around apple') 26 | 27 | except Exception as e: 28 | sys.exit(e) 29 | 30 | else: 31 | sys.exit('result: ' + str(result)) 32 | -------------------------------------------------------------------------------- /tests/test_text.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import unittest 3 | 4 | try: 5 | from .abstract import AbstractTest 6 | except ImportError: 7 | from abstract import AbstractTest 8 | 9 | 10 | class TextTest(AbstractTest): 11 | def test_only_text(self): 12 | 13 | sends = { 14 | 'method': 'post', 15 | 'textcaptcha': 'Today is monday?', 16 | } 17 | 18 | return self.send_return(sends, 19 | self.solver.text, 20 | text='Today is monday?') 21 | 22 | def test_all_params(self): 23 | 24 | params = { 25 | 'text': 'Today is monday?', 26 | 'lang': 'en', 27 | } 28 | 29 | sends = { 30 | 'method': 'post', 31 | 'textcaptcha': 'Today is monday?', 32 | 'lang': 'en', 33 | } 34 | 35 | return self.send_return(sends, self.solver.text, **params) 36 | 37 | 38 | if __name__ == '__main__': 39 | 40 | unittest.main() 41 | -------------------------------------------------------------------------------- /examples/recaptcha_v3.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.recaptcha( 22 | sitekey='6LfdxboZAAAAAMtnONIt4DJ8J1t4wMC-kVG02zIO', 23 | url='https://mysite.com/page/with//recaptcha-v3', 24 | action='login', 25 | version='v3') 26 | 27 | except Exception as e: 28 | sys.exit(e) 29 | 30 | else: 31 | sys.exit('result: ' + str(result)) 32 | -------------------------------------------------------------------------------- /examples/rotate_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key, defaultTimeout=100, pollingInterval=10) 19 | 20 | try: 21 | result = solver.rotate( 22 | './images/rotate.jpg', 23 | angle=40, 24 | lang='en', 25 | # hintImg = 'images/rotate_hint.jpg' 26 | hintText='Put the images in the correct way up') 27 | 28 | except Exception as e: 29 | sys.exit(e) 30 | 31 | else: 32 | sys.exit('result: ' + str(result)) 33 | -------------------------------------------------------------------------------- /examples/funcaptcha.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 4 | 5 | from solvecaptcha import Solvecaptcha 6 | 7 | # In this example, we store the API key in environment variables, which can be set as follows: 8 | # On Linux or macOS: 9 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 10 | # On Windows: 11 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # Alternatively, you can directly assign the API key to a variable: 13 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 14 | 15 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 16 | 17 | solver = Solvecaptcha(api_key) 18 | 19 | try: 20 | result = solver.funcaptcha(sitekey='1C2BB537-D5F7-4A66-BC74-25881B58F1D6', 21 | url='https://agoda-api.arkoselabs.com/v2/1C2BB537-D5F7-4A66-BC74-25881B58F1D6/api.js', 22 | surl='https://client-api.arkoselabs.com') 23 | 24 | 25 | except Exception as e: 26 | sys.exit(e) 27 | 28 | else: 29 | sys.exit('result: ' + str(result)) 30 | -------------------------------------------------------------------------------- /examples/canvas_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 4 | 5 | from solvecaptcha import Solvecaptcha 6 | 7 | # In this example, we store the API key in environment variables, which can be set as follows: 8 | # On Linux or macOS: 9 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 10 | # On Windows: 11 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # Alternatively, you can directly assign the API key to a variable: 13 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 14 | 15 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 16 | 17 | solver = Solvecaptcha(api_key, defaultTimeout=120, pollingInterval=5, server='solvecaptcha.com') 18 | 19 | try: 20 | result = solver.canvas( 21 | './images/canvas.jpg', 22 | previousId=0, 23 | canSkip=0, 24 | lang='en', 25 | hintImg='./images/canvas_hint.jpg', 26 | hintText='Draw around apple', 27 | ) 28 | 29 | except Exception as e: 30 | sys.exit(e) 31 | 32 | else: 33 | sys.exit('result: ' + str(result)) 34 | -------------------------------------------------------------------------------- /examples/coordinates_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key, defaultTimeout=120, pollingInterval=5, extendedResponse=True) 19 | 20 | try: 21 | result = solver.coordinates('./images/grid_2.jpg', 22 | lang='en', 23 | hintImg='./images/grid_hint.jpg', 24 | hintText='Select all images with an Orange') 25 | except Exception as e: 26 | sys.exit(e) 27 | 28 | else: 29 | sys.exit('result: ' + str(result)) 30 | -------------------------------------------------------------------------------- /examples/grid_base64.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | from base64 import b64encode 4 | 5 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 6 | 7 | from solvecaptcha import Solvecaptcha 8 | 9 | # In this example, we store the API key in environment variables, which can be set as follows: 10 | # On Linux or macOS: 11 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # On Windows: 13 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 14 | # Alternatively, you can directly assign the API key to a variable: 15 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 16 | 17 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 18 | 19 | solver = Solvecaptcha(api_key) 20 | 21 | with open('./images/grid_2.jpg', 'rb') as f: 22 | b64 = b64encode(f.read()).decode('utf-8') 23 | 24 | try: 25 | result = solver.grid(b64, 26 | hintText='Select all images with an Orange', 27 | rows=3, 28 | cols=3) 29 | 30 | except Exception as e: 31 | sys.exit(e) 32 | 33 | else: 34 | sys.exit('result: ' + str(result)) 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Solvecaptcha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/keycaptcha.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.keycaptcha( 22 | s_s_c_user_id=184015, 23 | s_s_c_session_id='e34ddd2c72e67593ac0b4ca8e4f44725', 24 | s_s_c_web_server_sign='a5ebd41ae22348b2cdbdc211792e982d', 25 | s_s_c_web_server_sign2='29255689423dd92990f8d06de50560d0', 26 | url='https://mysite.com/page/with//keycaptcha') 27 | 28 | except Exception as e: 29 | sys.exit(e) 30 | 31 | else: 32 | sys.exit('result: ' + str(result)) 33 | -------------------------------------------------------------------------------- /examples/grid_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key, defaultTimeout=100, pollingInterval=12) 19 | 20 | try: 21 | result = solver.grid( 22 | file='./images/grid_2.jpg', 23 | rows=3, 24 | cols=3, 25 | previousId=0, 26 | canSkip=0, 27 | lang='en', 28 | hintImg='./images/grid_hint.jpg', 29 | # hintText='Select all images with an Orange', 30 | ) 31 | 32 | except Exception as e: 33 | sys.exit(e) 34 | 35 | else: 36 | sys.exit('result: ' + str(result)) 37 | -------------------------------------------------------------------------------- /examples/normal_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key, defaultTimeout=30, pollingInterval=5) 19 | 20 | try: 21 | result = solver.normal( 22 | './images/normal_2.jpg', 23 | numeric=4, 24 | minLen=4, 25 | maxLen=20, 26 | phrase=0, 27 | caseSensitive=0, 28 | calc=0, 29 | lang='en', 30 | # hintImg='./images/normal_hint.jpg', 31 | # hintText='Type red symbols only', 32 | ) 33 | 34 | except Exception as e: 35 | sys.exit(e) 36 | 37 | else: 38 | sys.exit('result: ' + str(result)) 39 | -------------------------------------------------------------------------------- /tests/test_geetest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | try: 6 | from .abstract import AbstractTest 7 | except ImportError: 8 | from abstract import AbstractTest 9 | 10 | 11 | 12 | class GeeTest(AbstractTest): 13 | 14 | 15 | def test_all_params(self): 16 | 17 | 18 | params = { 19 | 'gt' : 'f2ae6cadcf7886856696502e1d55e00c', 20 | 'apiServer' : 'api-na.geetest.com', 21 | 'challenge' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', 22 | 'url' : 'https://launches.endclothing.com/distil_r_captcha.html', } 23 | 24 | sends = { 25 | 'method' : 'geetest', 26 | 'gt' : 'f2ae6cadcf7886856696502e1d55e00c', 27 | 'api_server' : 'api-na.geetest.com', 28 | 'challenge' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', 29 | 'pageurl' : 'https://launches.endclothing.com/distil_r_captcha.html', 30 | } 31 | 32 | return self.send_return(sends, self.solver.geetest, **params) 33 | 34 | 35 | 36 | 37 | 38 | if __name__ == '__main__': 39 | 40 | unittest.main() 41 | 42 | -------------------------------------------------------------------------------- /examples/turnstile.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | try: 21 | result = solver.turnstile( 22 | sitekey='0x4AAAAAAAFhFmVSpJiMM20Z', 23 | url='https://tvboom.net/packages/view/id/1/packages/view/id/1/', 24 | useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", 25 | ) 26 | 27 | # {"sitekey":"0x4AAAAAAAFhFmVSpJiMM20Z","pageurl":"https:\/\/tvboom.net\/packages\/view\/id\/1\/packages\/view\/id\/1\/","pagedata":"","captchatype":"turnstile","data":"","action":"",","proxy":"","proxytype":"HTTP"} 28 | 29 | except Exception as e: 30 | sys.exit(e) 31 | 32 | else: 33 | sys.exit('result: ' + str(result)) 34 | -------------------------------------------------------------------------------- /examples/geetest.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import requests 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key) 19 | 20 | """ 21 | Important: The value of the 'challenge' parameter is dynamic. You must obtain a new value for each request to our API. 22 | """ 23 | 24 | resp = requests.get("https://mysite.com/api/v1/ captcha-demo/gee-test/init-params") 25 | challenge = resp.json()['challenge'] 26 | 27 | try: 28 | result = solver.geetest(gt='81388ea1fc187e0c335c0a8907ff2625', 29 | apiServer='http://api.geetest.com', 30 | challenge=challenge, 31 | url='https://mysite.com/page/with//geetest') 32 | 33 | except Exception as e: 34 | sys.exit(e) 35 | 36 | else: 37 | sys.exit('result: ' + str(result)) -------------------------------------------------------------------------------- /tests/test_keycaptcha.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | try: 6 | from .abstract import AbstractTest 7 | except ImportError: 8 | from abstract import AbstractTest 9 | 10 | 11 | 12 | class KeyCaptchaTest(AbstractTest): 13 | 14 | 15 | def test_all_params(self): 16 | 17 | 18 | params = { 19 | 's_s_c_user_id' : 10, 20 | 's_s_c_session_id' : '493e52c37c10c2bcdf4a00cbc9ccd1e8', 21 | 's_s_c_web_server_sign' : '9006dc725760858e4c0715b835472f22-pz-', 22 | 's_s_c_web_server_sign2' : '2ca3abe86d90c6142d5571db98af6714', 23 | 'url' : 'https://www.keycaptcha.ru/demo-magnetic/', 24 | } 25 | 26 | sends = { 27 | 'method' : 'keycaptcha', 28 | 's_s_c_user_id' : 10, 29 | 's_s_c_session_id' : '493e52c37c10c2bcdf4a00cbc9ccd1e8', 30 | 's_s_c_web_server_sign' : '9006dc725760858e4c0715b835472f22-pz-', 31 | 's_s_c_web_server_sign2' : '2ca3abe86d90c6142d5571db98af6714', 32 | 'pageurl' : 'https://www.keycaptcha.ru/demo-magnetic/', 33 | } 34 | 35 | return self.send_return(sends, self.solver.keycaptcha, **params) 36 | 37 | 38 | 39 | 40 | 41 | if __name__ == '__main__': 42 | 43 | unittest.main() 44 | 45 | -------------------------------------------------------------------------------- /examples/funcaptcha_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 4 | 5 | from solvecaptcha import Solvecaptcha 6 | 7 | # In this example, we store the API key in environment variables, which can be set as follows: 8 | # On Linux or macOS: 9 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 10 | # On Windows: 11 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 12 | # Alternatively, you can directly assign the API key to a variable: 13 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 14 | 15 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 16 | 17 | solver = Solvecaptcha(api_key, defaultTimeout=180, pollingInterval=15) 18 | 19 | try: 20 | result = solver.funcaptcha( 21 | sitekey='1C2BB537-D5F7-4A66-BC74-25881B58F1D6', 22 | url='https://agoda-api.arkoselabs.com/v2/1C2BB537-D5F7-4A66-BC74-25881B58F1D6/api.js', 23 | surl='https://client-api.arkoselabs.com', 24 | userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36', 25 | # **{'data[key]': 'value'}, #optional data param used by some websites 26 | # proxy={ 27 | # 'type': 'HTTP', 28 | # 'uri': 'login:password@123.123.123.123:8080' 29 | # } 30 | ) 31 | 32 | except Exception as e: 33 | sys.exit(e) 34 | 35 | else: 36 | sys.exit('result: ' + str(result)) 37 | -------------------------------------------------------------------------------- /tests/test_funcaptcha.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | try: 6 | from .abstract import AbstractTest 7 | except ImportError: 8 | from abstract import AbstractTest 9 | 10 | 11 | 12 | class FuncaptchaTest(AbstractTest): 13 | 14 | 15 | def test_all_params(self): 16 | 17 | 18 | params = { 19 | 'sitekey' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', 20 | 'url' : 'https://mysite.com/page/with/funcaptcha', 21 | 'surl' : 'https://client-api.arkoselabs.com', 22 | 'userAgent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36', 23 | 'data' : {'anyKey' : 'anyStringValue'}, 24 | } 25 | 26 | sends = { 27 | 'method' : 'funcaptcha', 28 | 'publickey' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC', 29 | 'pageurl' : 'https://mysite.com/page/with/funcaptcha', 30 | 'surl' : 'https://client-api.arkoselabs.com', 31 | 'userAgent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36', 32 | 'data' : {'anyKey' : 'anyStringValue'}, 33 | } 34 | 35 | return self.send_return(sends, self.solver.funcaptcha, **params) 36 | 37 | 38 | 39 | 40 | 41 | if __name__ == '__main__': 42 | 43 | unittest.main() 44 | 45 | -------------------------------------------------------------------------------- /examples/recaptcha_v3_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | 19 | config = { 20 | 'server': 'solvecapcha.com', 21 | 'apiKey': api_key, 22 | # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. 23 | 'defaultTimeout': 120, 24 | 'recaptchaTimeout': 600, 25 | 'pollingInterval': 10, 26 | } 27 | 28 | solver = Solvecaptcha(**config) 29 | 30 | try: 31 | result = solver.recaptcha( 32 | sitekey='6LfdxboZAAAAAMtnONIt4DJ8J1t4wMC-kVG02zIO', 33 | url='https://mysite.com/page/with//recaptcha-v3', 34 | version='v3', 35 | action='verify', 36 | # proxy={ 37 | # 'type': 'HTTPS', 38 | # 'uri': 'login:password@IP_address:PORT' 39 | # } 40 | ) 41 | 42 | except Exception as e: 43 | sys.exit(e) 44 | 45 | else: 46 | sys.exit('result: ' + str(result)) 47 | -------------------------------------------------------------------------------- /examples/geetest_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import requests 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | solver = Solvecaptcha(api_key, 19 | defaultTimeout=300, 20 | pollingInterval=10, 21 | extendedResponse=True) 22 | 23 | """ 24 | **Important:** The value of the `challenge` parameter is dynamic. You must obtain a new value for each request to our API. 25 | """ 26 | 27 | resp = requests.get("https://mysite.com/api/v1/ captcha-demo/gee-test/init-params") 28 | challenge = resp.json()['challenge'] 29 | 30 | try: 31 | result = solver.geetest( 32 | gt='81388ea1fc187e0c335c0a8907ff2625', 33 | apiServer='http://api.geetest.com', 34 | challenge=challenge, 35 | url='https://mysite.com/page/with//geetest', 36 | # proxy={ 37 | # 'type': 'HTTPS', 38 | # 'uri': 'login:password@IP_address:PORT' 39 | # } 40 | ) 41 | 42 | except Exception as e: 43 | sys.exit(e) 44 | 45 | else: 46 | sys.exit('result: ' + str(result)) -------------------------------------------------------------------------------- /examples/recaptcha_v2_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | 19 | config = { 20 | 'server': 'solvecaptcha.com', 21 | 'apiKey': api_key, 22 | # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. 23 | 'defaultTimeout': 120, 24 | 'recaptchaTimeout': 600, 25 | 'pollingInterval': 10, 26 | } 27 | 28 | solver = Solvecaptcha(**config) 29 | 30 | try: 31 | result = solver.recaptcha( 32 | sitekey='6LdO5_IbAAAAAAeVBL9TClS19NUTt5wswEb3Q7C5', 33 | url='https://mysite.com/page/with//recaptcha-v2-invisible', 34 | invisible=1, 35 | # header_acao=1, 36 | # pingback="http://mysite.com/pingback/url/", 37 | # proxy={'type': 'HTTPS', 38 | # 'uri': 'login:password@IP_address:PORT' 39 | # } 40 | ) 41 | 42 | except Exception as e: 43 | sys.exit(e) 44 | 45 | else: 46 | sys.exit('result: ' + str(result)) 47 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from setuptools import setup, find_packages 4 | import re 5 | 6 | with open("README.md", "r") as fh: 7 | long_description = fh.read() 8 | 9 | 10 | def get_version(): 11 | with open('solvecaptcha/__init__.py', 'r') as f: 12 | return re.search(r'__version__ = ["\'](.*?)["\']', f.read()).group(1) 13 | 14 | 15 | setup(name='solvecaptcha-python', 16 | version=get_version(), 17 | description='Python module for easy integration with solvecaptcha.com API', 18 | long_description=long_description, 19 | long_description_content_type="text/markdown", 20 | url='https://github.com/solvercaptcha/solvecaptcha-python/', 21 | install_requires=['requests'], 22 | author='solvecaptcha.com', 23 | author_email='info@solvecaptcha.com', 24 | packages=find_packages(), 25 | include_package_data=True, 26 | classifiers=[ 27 | "Programming Language :: Python :: 3", 28 | "License :: OSI Approved :: MIT License", 29 | "Operating System :: OS Independent", 30 | "Topic :: Software Development :: Libraries :: Python Modules", 31 | "Topic :: Scientific/Engineering :: Image Recognition", 32 | "Topic :: Utilities", 33 | "Intended Audience :: Developers", 34 | ], 35 | keywords=[ 36 | 'solvecaptcha', 'captcha', 'api', 'captcha solver', 'reCAPTCHA', 37 | 'FunCaptcha', 'Geetest', 'image captcha', 'Coordinates', 'Click Captcha', 38 | 'Geetest V4', 'Lemin captcha', 'Amazon WAF', 'Cloudflare Turnstile'], 39 | python_requires='>=3.6', 40 | test_suite='tests') 41 | -------------------------------------------------------------------------------- /examples/geetest_v4_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import requests 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | config = { 19 | 'server': 'solvecaptcha.com', 20 | 'apiKey': api_key, 21 | # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. 22 | 'defaultTimeout': 120, 23 | 'recaptchaTimeout': 600, 24 | 'pollingInterval': 10, 25 | } 26 | 27 | solver = Solvecaptcha(**config) 28 | 29 | try: 30 | result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73', 31 | url='https://mysite.com/page/with//geetest-v4', 32 | # proxy={ 33 | # 'type': 'HTTPS', 34 | # 'uri': 'login:password@IP_address:PORT' 35 | # } 36 | ) 37 | 38 | except Exception as e: 39 | sys.exit(e) 40 | 41 | else: 42 | sys.exit('result: ' + str(result)) 43 | -------------------------------------------------------------------------------- /examples/keycaptcha_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | 19 | config = { 20 | 'server': 'solvecaptcha.com', 21 | 'apiKey': api_key, 22 | # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. 23 | 'defaultTimeout': 120, 24 | 'recaptchaTimeout': 600, 25 | 'pollingInterval': 10, 26 | } 27 | 28 | solver = Solvecaptcha(**config) 29 | 30 | try: 31 | result = solver.keycaptcha(s_s_c_user_id=184015, 32 | s_s_c_session_id='e34ddd2c72e67593ac0b4ca8e4f44725', 33 | s_s_c_web_server_sign='a5ebd41ae22348b2cdbdc211792e982d', 34 | s_s_c_web_server_sign2='29255689423dd92990f8d06de50560d0', 35 | url='https://mysite.com/page/with//keycaptcha', 36 | # proxy = {'type': 'HTTPS', 37 | # 'uri': 'login:password@IP_address:PORT'} 38 | ) 39 | 40 | 41 | except Exception as e: 42 | sys.exit(e) 43 | 44 | else: 45 | sys.exit('result: ' + str(result)) 46 | 47 | -------------------------------------------------------------------------------- /tests/test_coordinates.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | 6 | file = '../examples/images/grid.jpg' 7 | hint_img = '../examples/images/grid_hint.jpg' 8 | hint_text = 'Select all images with an Orange' 9 | checks = {'coordinatescaptcha': 1} 10 | 11 | 12 | try: 13 | from .abstract import AbstractTest 14 | 15 | file = file[3:] 16 | hint_img = hint_img[3:] 17 | 18 | except ImportError: 19 | from abstract import AbstractTest 20 | 21 | 22 | 23 | 24 | 25 | 26 | class CoordinatesTest(AbstractTest): 27 | 28 | def test_file_param(self): 29 | 30 | sends = {'method': 'post', 'file': file, **checks} 31 | return self.send_return(sends, self.solver.coordinates, file=file) 32 | 33 | 34 | 35 | def test_base64_param(self): 36 | 37 | b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' 38 | sends = { 39 | 'method': 'base64', 40 | 'body' : b64, 41 | **checks, 42 | } 43 | 44 | return self.send_return(sends, self.solver.coordinates, file=b64) 45 | 46 | 47 | 48 | def test_all_params(self): 49 | 50 | params = { 51 | 'lang' : 'en', 52 | 'hintImg' : hint_img, 53 | 'hintText' : hint_text 54 | } 55 | 56 | 57 | sends = { 58 | 'method' : 'post', 59 | 'lang' : 'en', 60 | 'files' : {'file': file,'imginstructions': hint_img}, 61 | 'textinstructions' : hint_text, 62 | **checks 63 | } 64 | 65 | return self.send_return(sends, self.solver.coordinates, file=file, **params) 66 | 67 | 68 | 69 | def test_not_found(self): 70 | 71 | return self.invalid_file(self.solver.coordinates) 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | if __name__ == '__main__': 82 | 83 | unittest.main() 84 | 85 | -------------------------------------------------------------------------------- /tests/abstract.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import unittest 3 | import sys 4 | import os 5 | 6 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 7 | 8 | from solvecaptcha import Solvecaptcha 9 | 10 | captcha_id = '123' 11 | code = 'abcd' 12 | 13 | 14 | class ApiClient(): 15 | def in_(self, files={}, **kwargs): 16 | 17 | self.incomings = kwargs 18 | self.incoming_files = files 19 | 20 | return 'OK|' + captcha_id 21 | 22 | def res(self, **kwargs): 23 | 24 | return 'OK|' + code # {'code': code} 25 | 26 | 27 | class AbstractTest(unittest.TestCase): 28 | def setUp(self): 29 | 30 | self.solver = Solvecaptcha('API_KEY', pollingInterval=1) 31 | self.solver.api_client = ApiClient() 32 | 33 | def send_return(self, for_send, method, **kwargs): 34 | 35 | file = kwargs.pop('file', {}) 36 | file = kwargs.pop('files', file) 37 | 38 | result = method(file, **kwargs) if file else method(**kwargs) 39 | 40 | incomings = self.solver.api_client.incomings 41 | for_send.update({'key': 'API_KEY'}) 42 | for_send.update({'soft_id': 1000001}) 43 | 44 | files = for_send.pop('files', {}) 45 | self.assertEqual(incomings, for_send) 46 | 47 | incoming_files = self.solver.api_client.incoming_files 48 | incoming_files and self.assertEqual(incoming_files, files) 49 | 50 | self.assertIsInstance(result, dict) 51 | self.assertIn('code', result) 52 | self.assertEqual(result['code'], code) 53 | 54 | def invalid_file(self, method, **kwargs): 55 | 56 | self.assertRaises(self.solver.exceptions, method, 'lost_file', 57 | **kwargs) 58 | 59 | def too_many_files(self, method, **kwargs): 60 | 61 | files = ['../examples/images/rotate.jpg'] * (self.solver.max_files + 1) 62 | self.assertRaises(self.solver.exceptions, method, files, **kwargs) 63 | 64 | 65 | if __name__ == '__main__': 66 | 67 | unittest.main() 68 | -------------------------------------------------------------------------------- /tests/test_recaptcha.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | try: 6 | from .abstract import AbstractTest 7 | except ImportError: 8 | from abstract import AbstractTest 9 | 10 | 11 | 12 | class RecaptchaTest(AbstractTest): 13 | 14 | 15 | def test_v2(self): 16 | 17 | params = { 18 | 'sitekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', 19 | 'url' : 'https://mysite.com/page/with/recaptcha', 20 | 'invisible' : 1, 21 | 'action' : 'verify', 22 | } 23 | 24 | sends = { 25 | 'method' : 'userrecaptcha', 26 | 'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', 27 | 'pageurl' : 'https://mysite.com/page/with/recaptcha', 28 | 'invisible': 1, 29 | 'enterprise': 0, 30 | 'action' : 'verify', 31 | 'version' : 'v2', 32 | } 33 | 34 | return self.send_return(sends, self.solver.recaptcha, **params) 35 | 36 | 37 | def test_v3(self): 38 | 39 | params = { 40 | 'sitekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', 41 | 'url' : 'https://mysite.com/page/with/recaptcha', 42 | 'invisible' : 1, 43 | 'action' : 'verify', 44 | 'version' : 'v3', 45 | } 46 | 47 | sends = { 48 | 'method' : 'userrecaptcha', 49 | 'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', 50 | 'pageurl' : 'https://mysite.com/page/with/recaptcha', 51 | 'invisible' : 1, 52 | 'enterprise': 0, 53 | 'action' : 'verify', 54 | 'version' : 'v3', 55 | } 56 | 57 | return self.send_return(sends, self.solver.recaptcha, **params) 58 | 59 | 60 | 61 | if __name__ == '__main__': 62 | 63 | unittest.main() 64 | 65 | -------------------------------------------------------------------------------- /tests/test_grid.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | 6 | file = '../examples/images/grid.jpg' 7 | hint_img = '../examples/images/grid_hint.jpg' 8 | hint_text = 'Select all images with an Orange' 9 | 10 | 11 | try: 12 | from .abstract import AbstractTest 13 | 14 | file = file[3:] 15 | hint_img = hint_img[3:] 16 | 17 | except ImportError: 18 | from abstract import AbstractTest 19 | 20 | 21 | 22 | 23 | 24 | 25 | class GridTest(AbstractTest): 26 | 27 | def test_file_param(self): 28 | 29 | sends = {'method': 'post', 'file': file, 'recaptcha': 1} 30 | return self.send_return(sends, self.solver.grid, file=file) 31 | 32 | 33 | 34 | def test_base64_param(self): 35 | 36 | b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' 37 | sends = { 38 | 'method' : 'base64', 39 | 'body' : b64, 40 | 'recaptcha' : 1 41 | } 42 | 43 | return self.send_return(sends, self.solver.grid, file=b64) 44 | 45 | 46 | 47 | def test_all_params(self): 48 | 49 | params = { 50 | 'rows' : 3, 51 | 'cols' : 3, 52 | 'previousId' : 0, 53 | 'canSkip' : 0, 54 | 'lang' : 'en', 55 | 'hintImg' : hint_img, 56 | 'hintText' : hint_text 57 | } 58 | 59 | 60 | sends = { 61 | 'method' : 'post', 62 | 'recaptcha' : 1, 63 | 'recaptcharows' : 3, 64 | 'recaptchacols' : 3, 65 | 'previousID' : 0, 66 | 'can_no_answer' : 0, 67 | 'lang' : 'en', 68 | 'files' : {'file': file,'imginstructions': hint_img}, 69 | 'textinstructions' : hint_text, 70 | } 71 | 72 | return self.send_return(sends, self.solver.grid, file=file, **params) 73 | 74 | 75 | 76 | def test_not_found(self): 77 | 78 | return self.invalid_file(self.solver.grid) 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | if __name__ == '__main__': 89 | 90 | unittest.main() 91 | 92 | -------------------------------------------------------------------------------- /examples/turnstile_options.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 5 | 6 | from solvecaptcha import Solvecaptcha 7 | 8 | # In this example, we store the API key in environment variables, which can be set as follows: 9 | # On Linux or macOS: 10 | # export APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 11 | # On Windows: 12 | # set APIKEY_SOLVECAPTCHA=1abc234de56fab7c89012d34e56fa7b8 13 | # Alternatively, you can directly assign the API key to a variable: 14 | # api_key = "1abc234de56fab7c89012d34e56fa7b8" 15 | 16 | api_key = os.getenv('APIKEY_SOLVECAPTCHA', 'YOUR_API_KEY') 17 | 18 | 19 | config = { 20 | 'server': 'solvecaptcha.com', 21 | 'apiKey': api_key, 22 | # 'callback': 'https://your.site/result-receiver', # If set, the solver will return only the `captchaId` without polling the API for the answer. 23 | 'defaultTimeout': 120, 24 | 'recaptchaTimeout': 600, 25 | 'pollingInterval': 10, 26 | } 27 | 28 | solver = Solvecaptcha(**config) 29 | 30 | try: 31 | result = solver.turnstile(sitekey='0x4AAAAAAADnPIDROrmt1LDg', 32 | url='https://dexscreener.com/', 33 | data="8ffc47422ae4e297", 34 | pagedata="JD.BAzfWHWAX2ZIXTgOkwU7SIJIXB3TYI6x0fplCxPo-1736508032-1.3.1.1-2Qy7twd2XO5laG9G6QrjYSQ.g3LszfU1A1osszzbbz.EHIJLRM4lHyZMnyTex7nIl7U8xVZrb99.lVWJ6RSSWG.0x_95kiDv.kqnQACTDl072eVFdyd1IRA.3SJsKl0ptevnsQx6pShakPgm2HWX65d5Jv.CDvbLLPSDz1SJk35ULnsY0fC9B_7NfgjEai5D2sYdYx5XxIIOOrQLkOHD963SqC6DQu9VXq09o8qlWsjHEORy_4VOsxf.7hjBw9y3Auziyh7ISo2mgAEHqCnYMjJtyLDqc4CGSnmYBRvSGMj96KvTLfSx2PCNxwWpUiEHb1WcM9Y1zjyz6.JVos.mjx5MDQ3UADASMJbtdWHMpH0yDfiDgtWNpxW1F.chfJ.q5MhSip4lLAXMVYLMDi.10C0pjIhwOHM0tuFhbyjAoq7MOfvL9t0sNQLKlrk1RUayK6alVy2Y0Zf1BH4p7lOSPQ", 35 | action="managed", 36 | useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", 37 | # proxy={ 38 | # 'type': 'HTTPS', 39 | # 'uri': 'login:password@IP_address:PORT' 40 | # } 41 | ) 42 | 43 | except Exception as e: 44 | sys.exit(e) 45 | 46 | else: 47 | sys.exit('result: ' + str(result)) 48 | -------------------------------------------------------------------------------- /tests/test_normal.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | file = '../examples/images/normal.jpg' 6 | hint_img = '../examples/images/grid_hint.jpg' 7 | 8 | 9 | try: 10 | from .abstract import AbstractTest 11 | 12 | file = file[3:] 13 | hint_img = hint_img[3:] 14 | 15 | except ImportError: 16 | from abstract import AbstractTest 17 | 18 | 19 | 20 | 21 | class NormalTest(AbstractTest): 22 | 23 | def test_file(self): 24 | 25 | sends = {'method': 'post', 'file': file} 26 | return self.send_return(sends, self.solver.normal, file=file) 27 | 28 | 29 | 30 | # def test_file_params(self): 31 | 32 | # return self.test_send_return(self.method, self.file, method='post') 33 | 34 | 35 | 36 | def test_base64(self): 37 | 38 | b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' 39 | sends = { 40 | 'method': 'base64', 41 | 'body' : b64, 42 | } 43 | 44 | return self.send_return(sends, self.solver.normal, file=b64) 45 | 46 | 47 | 48 | def test_all_params(self): 49 | 50 | 51 | params = { 52 | 'numeric' : 4, 53 | 'minLen' : 4, 54 | 'maxLen' : 20, 55 | 'phrase' : 1, 56 | 'caseSensitive' : 1, 57 | 'calc' : 0, 58 | 'lang' : 'en', 59 | 'hintImg' : hint_img, 60 | 'hintText' : 'Type red symbols only', 61 | } 62 | 63 | 64 | sends = { 65 | 'files' : {'file': file,'imginstructions': hint_img}, 66 | 'method' : 'post', 67 | 'numeric' : 4, 68 | 'min_len' : 4, 69 | 'max_len' : 20, 70 | 'phrase' : 1, 71 | 'regsense' : 1, 72 | 'calc' : 0, 73 | 'lang' : 'en', 74 | 'textinstructions' : 'Type red symbols only', 75 | } 76 | 77 | # files = { 78 | # 'file' : file, 79 | # 'imginstructions' : hint, 80 | # } 81 | 82 | return self.send_return(sends, self.solver.normal, file=file, **params) 83 | 84 | 85 | 86 | def test_not_found(self): 87 | 88 | return self.invalid_file(self.solver.normal) 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | if __name__ == '__main__': 100 | 101 | unittest.main() 102 | 103 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and maintainers pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to creating a positive environment include: 12 | 13 | - Using welcoming and inclusive language 14 | - Being respectful of differing viewpoints and experiences 15 | - Gracefully accepting constructive criticism 16 | - Focusing on what is best for the community 17 | - Showing empathy toward other community members 18 | 19 | Examples of unacceptable behavior by participants include: 20 | 21 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 22 | - Trolling, insulting/derogatory comments, and personal or political attacks 23 | - Public or private harassment 24 | - Publishing others' private information, such as a physical or email address, without their explicit permission 25 | - Other conduct which could reasonably be considered inappropriate in a professional setting 26 | 27 | ## Our Responsibilities 28 | 29 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any instances of unacceptable behavior. 30 | 31 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 32 | 33 | ## Scope 34 | 35 | This Code of Conduct applies within all project spaces, both public and private, when an individual is representing the project or its community in any way. 36 | 37 | Examples of representing a project or community include using an official project email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 38 | 39 | ## Enforcement 40 | 41 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at info@solvecaptcha.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. 42 | 43 | If you have any questions or suggestions about this Code of Conduct, feel free to reach out to the project team. 44 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to solvecaptcha-python 2 | 3 | Thank you for considering contributing to the solvecaptcha-python! By contributing, you're helping improve the project and enabling others to benefit from your improvements. 4 | 5 | Here are a few guidelines to help you get started. 6 | 7 | ## How to Contribute 8 | 9 | 1. **Fork the repository** 10 | If you'd like to contribute, please start by forking the project and cloning it to your local machine. 11 | 12 | ```bash 13 | git clone https://github.com/solvercaptcha/solvecaptcha-python.git 14 | ``` 15 | 16 | 2. **Create a new branch** 17 | Create a new branch for your feature or bug fix. This will help keep your changes separate from the main codebase. 18 | 19 | ```bash 20 | git checkout -b my-feature-branch 21 | ``` 22 | 23 | 3. **Make your changes** 24 | Modify the code or documentation as needed. Make sure to follow the project's coding style and conventions. 25 | 26 | 4. **Test your changes** 27 | Ensure that your changes work as expected and do not break anything in the project. If applicable, write tests to cover your changes. 28 | 29 | 5. **Commit your changes** 30 | After you've made your changes, commit them with a meaningful message describing what you've done. 31 | 32 | ```bash 33 | git commit -m "Add feature X to bypass challenge" 34 | ``` 35 | 36 | 6. **Push your changes** 37 | Push your changes to your forked repository. 38 | 39 | ```bash 40 | git push origin my-feature-branch 41 | ``` 42 | 43 | 7. **Submit a pull request** 44 | Navigate to the original repository and submit a pull request. Describe the changes you've made and why they're important. 45 | 46 | We will review your pull request and get back to you as soon as possible! 47 | 48 | ## Reporting Issues 49 | 50 | If you find any bugs or issues with the project, feel free to open an issue in the **Issues** tab. When reporting an issue, please provide the following information: 51 | 52 | - A detailed description of the issue. 53 | - Steps to reproduce the issue. 54 | - Any relevant error messages or logs. 55 | 56 | ## Code of Conduct 57 | 58 | By contributing to this project, you agree to abide by our [Code of Conduct](./CODE_OF_CONDUCT.md). Please be respectful and considerate to other contributors. 59 | 60 | ## Types of Contributions 61 | 62 | Here are some ways you can contribute to the project: 63 | 64 | - **Bug Fixes**: If you find a bug, feel free to submit a pull request with a fix. 65 | - **Feature Requests**: Have a great idea for a new feature? Open an issue to discuss it! 66 | - **Documentation**: Help improve the documentation or add new guides to make the project more accessible to others. 67 | - **Tests**: Ensure that the project is thoroughly tested and improve the test coverage. 68 | - **Code Refactoring**: Help improve the project codebase by refactoring or optimizing the code. 69 | 70 | ## Thank You! 71 | 72 | Your contributions are greatly appreciated! Together, we can make this project even better for everyone. 73 | -------------------------------------------------------------------------------- /solvecaptcha/api.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | 5 | 6 | class NetworkException(Exception): 7 | pass 8 | 9 | 10 | class ApiException(Exception): 11 | pass 12 | 13 | 14 | class ApiClient(): 15 | def __init__(self, post_url='api.solvecaptcha.com'): 16 | self.post_url = post_url 17 | 18 | def in_(self, files={}, **kwargs): 19 | ''' 20 | 21 | sends POST-request (files and/or params) to solve captcha 22 | 23 | Parameters 24 | ---------- 25 | files : TYPE, optional 26 | DESCRIPTION. The default is {}. 27 | **kwargs : TYPE 28 | DESCRIPTION. 29 | 30 | Raises 31 | ------ 32 | NetworkException 33 | DESCRIPTION. 34 | ApiException 35 | DESCRIPTION. 36 | 37 | Returns 38 | ------- 39 | resp : TYPE 40 | DESCRIPTION. 41 | 42 | ''' 43 | 44 | try: 45 | current_url = 'https://' + self.post_url + '/in.php' 46 | if files: 47 | 48 | files = {key: open(path, 'rb') for key, path in files.items()} 49 | resp = requests.post(current_url, 50 | data=kwargs, 51 | files=files) 52 | 53 | [f.close() for f in files.values()] 54 | 55 | elif 'file' in kwargs: 56 | 57 | with open(kwargs.pop('file'), 'rb') as f: 58 | resp = requests.post(current_url, 59 | data=kwargs, 60 | files={'file': f}) 61 | 62 | else: 63 | resp = requests.post(current_url, 64 | data=kwargs) 65 | 66 | except requests.RequestException as e: 67 | raise NetworkException(e) 68 | 69 | if resp.status_code != 200: 70 | raise NetworkException(f'bad response: {resp.status_code}') 71 | 72 | resp = resp.content.decode('utf-8') 73 | 74 | if 'ERROR' in resp: 75 | raise ApiException(resp) 76 | 77 | return resp 78 | 79 | def res(self, **kwargs): 80 | ''' 81 | sends additional GET-requests (solved captcha, balance, report etc.) 82 | 83 | Parameters 84 | ---------- 85 | **kwargs : TYPE 86 | DESCRIPTION. 87 | 88 | Raises 89 | ------ 90 | NetworkException 91 | DESCRIPTION. 92 | ApiException 93 | DESCRIPTION. 94 | 95 | Returns 96 | ------- 97 | resp : TYPE 98 | DESCRIPTION. 99 | 100 | ''' 101 | 102 | try: 103 | current_url_out = 'https://' + self.post_url + '/res.php' 104 | resp = requests.get(current_url_out, params=kwargs) 105 | 106 | if resp.status_code != 200: 107 | raise NetworkException(f'bad response: {resp.status_code}') 108 | 109 | resp = resp.content.decode('utf-8') 110 | 111 | if 'ERROR' in resp: 112 | raise ApiException(resp) 113 | 114 | except requests.RequestException as e: 115 | raise NetworkException(e) 116 | 117 | return resp 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![solvecaptcha-python](https://github.com/user-attachments/assets/5270c365-83fd-4b37-9ff1-ff554e75442e) 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | # Python library for interacting with the Solvecaptcha API (captcha-solving service) 13 | 14 | A simple and efficient method to integrate the [Solvecaptcha] captcha-solving service into your code, enabling the automation of solving various types of captchas. 15 | Examples of API requests for different captcha types can be found on the [Python captcha solver](https://solvecaptcha.com/captcha-solver/python-captcha-solver-bypass) page. 16 | 17 | ## ✅ Supported captcha solvers 18 | To get started quickly, check out the [Captcha Solver API](https://solvecaptcha.com/captcha-solver-api) documentation. 19 | 20 | ### Helpful links: 21 | - [reCAPTCHA v2 solver (Python + Selenium)](https://solvecaptcha.com/captcha-solver/recaptcha-v2-solver-bypass) 22 | - [reCAPTCHA v3 solver](https://solvecaptcha.com/captcha-solver/recaptcha-v3-solver-bypass) 23 | - [Text & Image captcha solver (Base64 / file input)]() 24 | - [Cloudflare captcha / Turnstile solver](https://solvecaptcha.com/captcha-solver/cloudflare-captcha-solver-bypass) 25 | - [Amazon captcha (WAF & login forms)](https://solvecaptcha.com/captcha-solver/amazon-captcha-solver-bypass) 26 | - [GeeTest slider solver](https://solvecaptcha.com/captcha-solver/slider-captcha-solver-bypass) 27 | - [FunCaptcha (Arkose Labs)](https://solvecaptcha.com/captcha-solver/funcaptcha-solver-bypass) 28 | - [Other custom captcha types](https://solvecaptcha.com/) 29 | 30 | ## 🛠️ Features 31 | - Fast and fully automated captcha bypass 32 | - Works in **Python** environments 33 | - Compatible with **Selenium**, **Playwright**, and other browser automation tools 34 | - Lightweight SDK with modern **async/await** support 35 | - Pay only for successful solves 36 | - 99.9% uptime 37 | - 24/7 support for developers and integration teams 38 | 39 | ## 📦 Use cases 40 | 41 | - Web scraping behind reCAPTCHA or Cloudflare walls 42 | - Automated form submission and login flows 43 | - QA pipelines and headless browser testing 44 | - Bypassing captchas in research or bot-detection evaluation 45 | - Custom browser automations using Python 46 | 47 | Need help integrating with your Python app or automation tools? [Open an issue](https://github.com/solvercaptcha/solvecaptcha-python/issues) or fork this repo to contribute. 48 | 49 | - [Python Library for Interacting with the Solvecaptcha API](#python-library-for-interacting-with-the-solvecaptcha-api-captcha-solving-service) 50 | - [Installation](#installation) 51 | - [Configuration](#configuration) 52 | - [Solvecaptcha instance options](#solvecaptcha-instance-options) 53 | - [Solve captcha](#solve-captcha) 54 | - [Captcha options](#captcha-options) 55 | - [Normal Captcha](#normal-captcha) 56 | - [Text Captcha](#text-captcha) 57 | - [reCAPTCHA v2](#recaptcha-v2) 58 | - [reCAPTCHA v3](#recaptcha-v3) 59 | - [FunCaptcha](#funcaptcha) 60 | - [GeeTest](#geetest) 61 | - [GeeTest v4](#geetest-v4) 62 | - [Cloudflare Turnstile](#cloudflare-turnstile) 63 | - [KeyCaptcha](#keycaptcha) 64 | - [Grid](#grid) 65 | - [ClickCaptcha](#clickcaptcha) 66 | - [Rotate](#rotate) 67 | - [Other methods](#other-methods) 68 | - [send / get_result](#send--get_result) 69 | - [balance](#balance) 70 | - [report](#report) 71 | - [Error handling](#error-handling) 72 | - [Proxies](#proxies) 73 | - [Async calls](#async-calls) 74 | - [Examples](#examples) 75 | - [Examples using Selenium](#examples-using-selenium) 76 | - [Useful articles](#useful-articles) 77 | - [Get in touch](#get-in-touch) 78 | - [License](#license) 79 | 80 | ## Installation 81 | 82 | This package can be installed using Pip: 83 | 84 | ```bash 85 | pip3 install solvecaptcha-python 86 | ``` 87 | or You can install this package directly from GitHub using `pip`: 88 | 89 | ```sh 90 | pip install git+https://github.com/solvercaptcha/solvecaptcha-python.git 91 | ``` 92 | ## Configuration 93 | 94 | An instance of `Solvecaptcha` can be created as follows: 95 | 96 | ```python 97 | from solvecaptcha import Solvecaptcha 98 | 99 | solver = Solvecaptcha('YOUR_API_KEY') 100 | ``` 101 | 102 | Additionally, there are several options available for configuration: 103 | 104 | ```python 105 | config = { 106 | 'server': 'solvecaptcha.com', 107 | 'apiKey': 'YOUR_API_KEY', 108 | 'callback': 'https://your.site/result-receiver', 109 | 'defaultTimeout': 120, 110 | 'recaptchaTimeout': 600, 111 | 'pollingInterval': 10, 112 | 'extendedResponse': False 113 | } 114 | solver = Solvecaptcha(**config) 115 | ``` 116 | 117 | ### Solvecaptcha instance options 118 | 119 | | Option | Default value | Description | 120 | | ---------------- | ------------------ | -------------- | 121 | | server | `solvecaptcha.com` | API server. You can configure it to `solvecaptcha.com` if your account is registered on this platform. | 122 | | callback | - | The URL of your web server that receives the captcha recognition result. This URL must first be registered in your account's [pingback settings]. | 123 | | defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Specifies the duration for which the module attempts to retrieve the response from the `res.php` API endpoint. | 124 | | recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Specifies the duration for which the module attempts to retrieve the response from the `res.php` API endpoint. | 125 | | pollingInterval | 10 | Interval in seconds between requests to the `res.php` API endpoint. It is not recommended to set a value lower than 5 seconds. | 126 | | extendedResponse | None | Set to `True` to receive the response with additional fields or in a more structured format (enables `JSON` response from the `res.php` API endpoint). Recommended for [ClickCaptcha](#clickcaptcha) and [Canvas](#canvas). | 127 | 128 | > [!IMPORTANT] 129 | > Once `callback` is defined for the `Solvecaptcha` instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. 130 | 131 | To get the answer manually, use the [get_result method](#send--get_result). 132 | 133 | ## Solve captcha 134 | 135 | When submitting any image-based CAPTCHA, you can provide additional options to assist Solvecaptcha workers in solving it correctly. 136 | 137 | ### Captcha options 138 | 139 | | Option | Default Value | Description | 140 | | ------------- | ------------- | --------------------------------------------------------------------------------------------- | 141 | | numeric | 0 | Specifies whether the captcha consists only of numbers or includes other symbols. More details are available in the [API documentation][post options]. | 142 | | minLen | 0 | Sets the minimum length of the expected answer. | 143 | | maxLen | 0 | Sets the maximum length of the expected answer. | 144 | | phrase | 0 | Indicates whether the response consists of multiple words. | 145 | | caseSensitive | 0 | Determines if the response must match the original case. | 146 | | calc | 0 | Specifies if the captcha involves a mathematical calculation. | 147 | | lang | - | Defines the language of the captcha. Refer to the [list of supported languages]. | 148 | | hintImg | - | Provides an additional image as a hint for workers alongside the captcha. | 149 | | hintText | - | Displays a text hint or task description for workers along with the captcha. | 150 | 151 | 152 | Below, you can find basic examples for each captcha type. For more examples with all available options, check the [examples directory]. 153 | 154 | ### Normal Captcha 155 | 156 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_normal_captcha) 157 | 158 | To solve a standard captcha (distorted text on an image), use the following method. This method can also be applied for text recognition in any image. 159 | 160 | 161 | ```python 162 | result = solver.normal('path/to/captcha.jpg', param1=..., ...) 163 | # OR 164 | result = solver.normal('https://site-with-captcha.com/path/to/captcha.jpg', param1=..., ...) 165 | ``` 166 | 167 | ```python 168 | result = solver.audio('path/to/captcha.mp3', lang = 'lang', param1=..., ...) 169 | # OR 170 | result = solver.audio('https://site-with-captcha.com/path/to/captcha.mp3', lang = 'lang', param1=..., ...) 171 | ``` 172 | 173 | ### Text Captcha 174 | 175 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_text_captcha) 176 | 177 | This method can be used to solve captchas that require answering a question presented in plain text. 178 | 179 | ```python 180 | result = solver.text('If tomorrow is Saturday, what day is today?', param1=..., ...) 181 | ``` 182 | 183 | ### reCAPTCHA v2 184 | 185 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_recaptchav2_new) 186 | 187 | Use the following method to solve reCAPTCHA V2 and retrieve a token for bypassing the protection. 188 | 189 | ```python 190 | result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', 191 | url='https://mysite.com/page/with/recaptcha', 192 | param1=..., ...) 193 | ``` 194 | 195 | ### reCAPTCHA v3 196 | 197 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_recaptchav3) 198 | 199 | This method offers a reCAPTCHA V3 solver and returns a token. 200 | 201 | ```python 202 | result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', 203 | url='https://mysite.com/page/with/recaptcha-v3', 204 | version='v3', 205 | param1=..., ...) 206 | ``` 207 | 208 | ### FunCaptcha 209 | 210 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_funcaptcha_new) 211 | 212 | FunCaptcha (Arkoselabs) solving method that returns a token. 213 | 214 | ```python 215 | result = solver.funcaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', 216 | url='https://mysite.com/page/with/funcaptcha', 217 | param1=..., ...) 218 | 219 | ``` 220 | 221 | ### GeeTest 222 | 223 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_geetest) 224 | 225 | Method for solving GeeTest puzzle captcha. Returns a set of tokens in JSON format. 226 | 227 | ```python 228 | result = solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e', 229 | challenge='12345678abc90123d45678ef90123a456b', 230 | url='https://www.site.com/page/', 231 | param1=..., ...) 232 | 233 | ``` 234 | 235 | ### GeeTest v4 236 | 237 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_geetest_v4) 238 | 239 | Use this method to solve GeeTest v4. The response is returned in JSON format. 240 | 241 | ```python 242 | result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73', 243 | url='https://www.site.com/page/', 244 | param1=..., ...) 245 | 246 | ``` 247 | 248 | ### Cloudflare Turnstile 249 | 250 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_cloudflare_turnstile) 251 | 252 | Use this method to solve Cloudflare Turnstile. The response is returned as JSON containing the token. 253 | 254 | ```python 255 | result = solver.turnstile(sitekey='0x1AAAAAAAAkg0s2VIOD34y5', 256 | url='http://mysite.com/', 257 | data='foo', 258 | pagedata='bar', 259 | action='challenge', 260 | useragent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36') 261 | ``` 262 | 263 | ### KeyCaptcha 264 | 265 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_keycaptcha) 266 | 267 | Token-based method for solving KeyCaptcha. 268 | 269 | ```python 270 | result = solver.keycaptcha(s_s_c_user_id=10, 271 | s_s_c_session_id='493e52c37c10c2bcdf4a00cbc9ccd1e8', 272 | s_s_c_web_server_sign='9006dc725760858e4c0715b835472f22-pz-', 273 | s_s_c_web_server_sign2='2ca3abe86d90c6142d5571db98af6714', 274 | url='https://www.keycaptcha.ru/demo-magnetic/', 275 | param1=..., ...) 276 | 277 | ``` 278 | 279 | ### Grid 280 | 281 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_grid) 282 | 283 | The grid method was initially known as the Old reCAPTCHA V2 method. It can be used to bypass any captcha that requires selecting specific grid boxes on an image. Returns the numbers of the selected boxes. 284 | 285 | ```python 286 | result = solver.grid('path/to/captcha.jpg', param1=..., ...) 287 | ``` 288 | 289 | ### ClickCaptcha 290 | 291 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_clickcaptcha) 292 | 293 | The ClickCaptcha method returns the coordinates of specific points on the captcha image. It is useful when solving captchas that require clicking on designated areas within the image. 294 | 295 | ```python 296 | result = solver.coordinates('path/to/captcha.jpg', param1=..., ...) 297 | ``` 298 | 299 | ### Rotate 300 | 301 | [API method description.](https://solvecaptcha.com/captcha-solver-api#solving_rotatecaptcha) 302 | 303 | This method is used to solve captchas that require rotating an object. It is primarily utilized for bypassing FunCaptcha and returns the rotation angle. 304 | 305 | ```python 306 | result = solver.rotate('path/to/captcha.jpg', param1=..., ...) 307 | ``` 308 | 309 | ### Canvas 310 | 311 | [API method description.](https://solvecaptcha.com/captcha-solver-api#canvas) 312 | 313 | The canvas method is used for captchas that require drawing a line around an object in an image. It returns a set of point coordinates for constructing a polygon. 314 | 315 | ```python 316 | result = solver.canvas('path/to/captcha.jpg', param1=..., ...) 317 | ``` 318 | 319 | ## Other methods 320 | 321 | ### send / get_result 322 | 323 | These methods allow manual captcha submission and answer polling. The `send()` method supports sending any captcha type. To specify the captcha type, you must manually set the `method` parameter, for example, `method='recaptcha'` for solving reCAPTCHA. 324 | You can find the available values for the `method` parameter in the [API documentation](https://solvecaptcha.com/captcha-solver-api). 325 | 326 | Example of manually solving a Normal captcha: 327 | 328 | ```python 329 | import time 330 | . . . . . 331 | 332 | 333 | id = solver.send(file='path/to/captcha.jpg') 334 | time.sleep(20) 335 | 336 | code = solver.get_result(id) 337 | ``` 338 | 339 | ### balance 340 | 341 | [API method description.](https://solvecaptcha.com/captcha-solver-api#additional) 342 | 343 | Use this method to retrieve your account balance. 344 | 345 | ```python 346 | balance = solver.balance() 347 | ``` 348 | 349 | ### report 350 | 351 | [API method description.](https://solvecaptcha.com/captcha-solver-api#complain) 352 | 353 | Use this method to report whether a captcha answer was correct or incorrect. 354 | 355 | ```python 356 | solver.report(id, True) # captcha solved correctly 357 | solver.report(id, False) # captcha solved incorrectly 358 | ``` 359 | 360 | ## Error handling 361 | 362 | If an error occurs, the captcha solver throws an exception. Proper error handling is essential. We recommend using `try except` to manage exceptions. 363 | A complete list of possible errors can be found in the [API documentation](https://solvecaptcha.com/captcha-solver-api#error_handling). 364 | 365 | ```python 366 | try: 367 | result = solver.text('If tomorrow is Saturday, what day is today?') 368 | except ValidationException as e: 369 | # invalid parameters passed 370 | print(e) 371 | except NetworkException as e: 372 | # network error occurred 373 | print(e) 374 | except ApiException as e: 375 | # api respond with error 376 | print(e) 377 | except TimeoutException as e: 378 | # captcha is not solved so far 379 | print(e) 380 | ``` 381 | 382 | ## Proxies 383 | 384 | You can provide your proxy as an additional argument for the following methods: reCAPTCHA, FunCaptcha, GeeTest, GeeTest v4, KeyCaptcha, Turnstile, Amazon WAF, and other captchas. 385 | 386 | The proxy will be passed to the API to facilitate captcha solving. 387 | 388 | We also offer our own proxies that you can use. 389 | 390 | ```python 391 | proxy={ 392 | 'type': 'HTTPS', 393 | 'uri': 'login:password@IP_address:PORT' 394 | } 395 | ``` 396 | 397 | ## Async calls 398 | 399 | You can also perform asynchronous calls using [asyncio], for example: 400 | 401 | ```python 402 | import asyncio 403 | import concurrent.futures 404 | from solvecaptcha import Solvecaptcha 405 | 406 | API_KEY = "YOUR_API_KEY" 407 | image = "data:image/png;base64,iVBORw0KGgoA..." 408 | 409 | async def captchaSolver(image): 410 | loop = asyncio.get_running_loop() 411 | with concurrent.futures.ThreadPoolExecutor() as pool: 412 | result = await loop.run_in_executor(pool, lambda: Solvecaptcha(API_KEY).normal(image)) 413 | return result 414 | 415 | captcha_result = asyncio.run(captchaSolver(image)) 416 | ``` 417 | 418 | ## Examples 419 | 420 | Examples of solving all supported captcha types can be found in the [examples] directory. 421 | 422 | ## Examples using Selenium 423 | 424 | We also have a separate repository where you can find examples of captcha solving using the [Selenium](https://pypi.org/project/selenium/) \ [seleniumbase](https://seleniumbase.io/) library. 425 | 426 | ## Useful articles 427 | 428 | - [Solve and bypass Google reCAPTCHA, Image CAPTCHA, Cloudflare Challenge and any captcha in Selenium with captcha solver.](https://solvecaptcha.com/captcha-solver/selenium-captcha-solver-bypass) 429 | - [Solve and bypass Google reCAPTCHA, Arkose FunCaptcha, Cloudflare Turnstile, and any captcha in Puppeteer with captcha solver.](https://solvecaptcha.com/captcha-solver/puppeteer-captcha-solver-bypass) 430 | 431 | ## Get in touch 432 | 433 | 434 | 435 | 436 | ## License 437 | 438 | The code in this repository is licensed under the MIT License. For more details, see the [LICENSE](./LICENSE) file. 439 | 440 | 441 | [Solvecaptcha]: https://solvecaptcha.com/ 442 | [pingback settings]: https://solvecaptcha.com/captcha-solver-api#manage_pingback 443 | [post options]: https://solvecaptcha.com/captcha-solver-api#normal_post 444 | [list of supported languages]: https://solvecaptcha.com/captcha-solver-api#language 445 | [examples directory]: /examples 446 | [asyncio]: https://docs.python.org/3/library/asyncio.html 447 | [examples]: ./examples 448 | -------------------------------------------------------------------------------- /solvecaptcha/solver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os, sys 4 | import time 5 | import requests 6 | from base64 import b64encode 7 | 8 | 9 | try: 10 | from .api import ApiClient 11 | 12 | except ImportError: 13 | from api import ApiClient 14 | 15 | 16 | class SolverExceptions(Exception): 17 | pass 18 | 19 | 20 | class ValidationException(SolverExceptions): 21 | pass 22 | 23 | 24 | class NetworkException(SolverExceptions): 25 | pass 26 | 27 | 28 | class ApiException(SolverExceptions): 29 | pass 30 | 31 | 32 | class TimeoutException(SolverExceptions): 33 | pass 34 | 35 | 36 | class Solvecaptcha(): 37 | def __init__(self, 38 | apiKey, 39 | softId=4844, 40 | callback=None, 41 | defaultTimeout=120, 42 | recaptchaTimeout=600, 43 | pollingInterval=10, 44 | server = 'api.solvecaptcha.com', 45 | extendedResponse=None): 46 | 47 | self.API_KEY = apiKey 48 | self.soft_id = softId 49 | self.callback = callback 50 | self.default_timeout = defaultTimeout 51 | self.recaptcha_timeout = recaptchaTimeout 52 | self.polling_interval = pollingInterval 53 | self.api_client = ApiClient(post_url = str(server)) 54 | self.max_files = 9 55 | self.exceptions = SolverExceptions 56 | self.extendedResponse = extendedResponse 57 | 58 | def recaptcha(self, sitekey, url, version='v2', enterprise=0, **kwargs): 59 | '''Wrapper for solving recaptcha (v2, v3). 60 | 61 | Parameters 62 | _______________ 63 | sitekey : str 64 | Value of sitekey parameter you found on page. 65 | url : str 66 | Full URL of the page where you see the reCAPTCHA. 67 | domain : str, optional 68 | Domain used to load the captcha: google.com or recaptcha.net. Default: google.com. 69 | invisible : int, optional 70 | 1 - means that reCAPTCHA is invisible. 0 - normal reCAPTCHA. Default: 0. 71 | version : str, optional 72 | v3 — defines that you're sending a reCAPTCHA V3. Default: v2. 73 | enterprise : str, optional 74 | 1 - defines that you're sending reCAPTCHA Enterpise. Default: 0. 75 | action : str, optional 76 | Value of action parameter you found on page. Default: verify. 77 | score : str, only for v3, optional 78 | The score needed for resolution. Currently, it's almost impossible to get token with score higher than 0.3. 79 | Default: 0.4. 80 | cookies : str, only for v2, optional 81 | Your cookies that will be passed to our worker who solve the captha. We also return worker's cookies in the 82 | response if you use json=1. Format: KEY:Value, separator: semicolon, example: KEY1:Value1;KEY2:Value2; 83 | userAgent : str, only for v2, optional 84 | Your userAgent that will be passed to our worker and used to solve the captcha. 85 | callback : str, optional 86 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 87 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 88 | proxy : dict, optional 89 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 90 | ''' 91 | 92 | params = { 93 | 'googlekey': sitekey, 94 | 'url': url, 95 | 'method': 'userrecaptcha', 96 | 'version': version, 97 | 'enterprise': enterprise, 98 | **kwargs, 99 | } 100 | 101 | result = self.solve(timeout=self.recaptcha_timeout, **params) 102 | return result 103 | 104 | def turnstile(self, sitekey, url, **kwargs): 105 | '''Wrapper for solving Cloudflare Turnstile. 106 | 107 | Parameters 108 | __________ 109 | sitekey : str 110 | Value of sitekey parameter you found on page. 111 | url : str 112 | Full URL of the page where you see the captcha. 113 | useragent : str 114 | User-Agent of your browser. Must match the User-Agent you use to access the site. 115 | Use only modern browsers released within the last 6 months. 116 | action : str. optional 117 | Value of optional action parameter you found on page, can be defined in data-action attribute or passed 118 | to turnstile.render call. 119 | data : str, optional 120 | The value of cData passed to turnstile.render call. Also can be defined in data-cdata attribute. 121 | pagedata : str, optional 122 | The value of the chlPageData parameter when calling turnstile.render. 123 | callback : str, optional 124 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 125 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 126 | proxy : dict, optional 127 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 128 | ''' 129 | 130 | result = self.solve(sitekey=sitekey, 131 | url=url, 132 | method='turnstile', 133 | **kwargs) 134 | return result 135 | 136 | def geetest(self, gt, challenge, url, **kwargs): 137 | '''Wrapper for solving geetest captcha. 138 | 139 | Parameters: 140 | __________ 141 | gt : str 142 | Value of gt parameter you found on target website. 143 | challenge : str 144 | Value of challenge parameter you found on target website. 145 | url : str 146 | Full URL of the page where you see Geetest captcha. 147 | offline : num, optional 148 | In rare cases initGeetest can be called with offline parameter. If the call uses offline: true, set the 149 | value to 1. Default: 0. 150 | new_captcha : num, optional 151 | In rare cases initGeetest can be called with new_captcha parameter. If the call uses new_captcha: true, set 152 | the value to 1. Mostly used with offline parameter. 153 | userAgent : str, optional 154 | Your userAgent that will be passed to our worker and used to solve the captcha. 155 | apiServer : str, optional 156 | Value of api_server parameter you found on target website. 157 | callback : str, optional 158 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 159 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 160 | proxy : dict, optional 161 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 162 | ''' 163 | 164 | result = self.solve(gt=gt, 165 | challenge=challenge, 166 | url=url, 167 | method='geetest', 168 | **kwargs) 169 | return result 170 | 171 | def geetest_v4(self, captcha_id, url, **kwargs): 172 | '''Wrapper for solving geetest_v4 captcha. 173 | 174 | Parameters 175 | __________ 176 | captcha_id : str 177 | Value of captcha_id parameter you found on target website. 178 | url: str 179 | Full URL of the page where you see Geetest captcha. 180 | callback : str, optional 181 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 182 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 183 | proxy : dict, optional 184 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 185 | ''' 186 | 187 | result = self.solve(captcha_id=captcha_id, 188 | url=url, 189 | method='geetest_v4', 190 | **kwargs) 191 | return result 192 | 193 | def normal(self, file, **kwargs): 194 | '''Wrapper for solving a normal captcha (image). 195 | 196 | Parameters 197 | __________ 198 | file : file 199 | Captcha image file. * required if you submit image as a file (method=post). 200 | body : str 201 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). 202 | phrase : int, optional 203 | 0 - captcha contains one word. 1 - captcha contains two or more words. 204 | Default: 0. 205 | numeric : int, optional 206 | 0 - not specified. 1 - captcha contains only numbers. 2 - captcha contains only letters. 3 - captcha 207 | contains only numbers OR only letters. 4 - captcha MUST contain both numbers AND letters. 208 | Default: 0 209 | minLen : int, optional 210 | 0 - not specified. 1..20 - minimal number of symbols in captcha. 211 | Default: 0. 212 | maxLen : int, optional 213 | 0 - not specified. 1..20 - maximal number of symbols in captcha. 214 | Default: 0. 215 | caseSensitive : int, optional 216 | 0 - captcha in not case sensitive. 1 - captcha is case sensitive. 217 | Default: 0. 218 | calc : int, optional 219 | 0 - not specified. 1 - captcha requires calculation (e.g. type the result 4 + 8 = ). 220 | Default: 0. 221 | lang : str, optional 222 | Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. 223 | hintText : str, optional 224 | Max 140 characters. Endcoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly. 225 | For example: type red symbols only. 226 | hintImg : img, optional 227 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending 228 | instruction as text with textinstructions. 229 | callback : str, optional 230 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 231 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 232 | ''' 233 | 234 | method = self.get_method(file) 235 | result = self.solve(**method, **kwargs) 236 | return result 237 | 238 | def text(self, text, **kwargs): 239 | '''Wrapper for solving text captcha. 240 | 241 | Parameters 242 | __________ 243 | text : str 244 | Max 140 characters. Endcoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly. 245 | For example: type red symbols only. 246 | lang: str, optional 247 | Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. 248 | callback : str, optional 249 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 250 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 251 | ''' 252 | 253 | result = self.solve(text=text, method='post', **kwargs) 254 | return result 255 | 256 | def funcaptcha(self, sitekey, url, **kwargs): 257 | '''Wrapper for solving funcaptcha. 258 | 259 | Parameters 260 | __________ 261 | sitekey : str 262 | Value of pk or data-pkey parameter you found on page. 263 | url : str 264 | Full URL of the page where you see the FunCaptcha. 265 | surl : str, optional 266 | Value of surl parameter you found on page. 267 | userAgent: str, optional 268 | Tells us to use your user-agent value. 269 | data[key] : str, optional 270 | Custom data to pass to FunCaptcha. For example: data[blob]=stringValue. 271 | callback : str, optional 272 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 273 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 274 | proxy : dict, optional 275 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 276 | ''' 277 | 278 | result = self.solve(publickey=sitekey, 279 | url=url, 280 | method='funcaptcha', 281 | **kwargs) 282 | return result 283 | 284 | def keycaptcha(self, s_s_c_user_id, s_s_c_session_id, 285 | s_s_c_web_server_sign, s_s_c_web_server_sign2, url, 286 | **kwargs): 287 | '''Wrapper for solving. 288 | 289 | Parameters 290 | __________ 291 | s_s_c_user_id : str 292 | Value of s_s_c_user_id parameter you found on page. 293 | s_s_c_session_id : str 294 | Value of s_s_c_session_id parameter you found on page. 295 | s_s_c_web_server_sign : str 296 | Value of s_s_c_web_server_sign parameter you found on page. 297 | s_s_c_web_server_sign2 : str 298 | Value of s_s_c_web_server_sign2 parameter you found on page. 299 | url : str 300 | Full URL of the page where you see the KeyCaptcha. 301 | callback : str, optional 302 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 303 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 304 | proxy : dict, optional 305 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 306 | ''' 307 | 308 | params = { 309 | 's_s_c_user_id': s_s_c_user_id, 310 | 's_s_c_session_id': s_s_c_session_id, 311 | 's_s_c_web_server_sign': s_s_c_web_server_sign, 312 | 's_s_c_web_server_sign2': s_s_c_web_server_sign2, 313 | 'url': url, 314 | 'method': 'keycaptcha', 315 | **kwargs, 316 | } 317 | 318 | result = self.solve(**params) 319 | return result 320 | 321 | def grid(self, file, **kwargs): 322 | '''Wrapper for solving grid captcha (image). 323 | 324 | Required: 325 | file : file 326 | Captcha image file. * required if you submit image as a file (method=post). 327 | body : str 328 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). 329 | hintText : str 330 | Max 140 characters. Endcoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select images 331 | with trees. Not required if you're sending instruction as an image with imginstructions. 332 | hintImg : img 333 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending 334 | instruction as text with textinstructions. 335 | rows : int, optional 336 | Number of rows in reCAPTCHA grid. 337 | cols : itn, optional 338 | Number of columns in reCAPTCHA grid. 339 | previousId : str, optional 340 | Id of your previous request with the same captcha challenge. 341 | canSkip : int, optional 342 | 0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's 343 | possible that there's no images matching to the instruction. We'll provide a button "No matching images" to 344 | worker, and you will receive No_matching_images as answer. 345 | Default: 0. 346 | lang: str, optional 347 | Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. 348 | callback : str, optional 349 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 350 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 351 | proxy : dict, optional 352 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 353 | ''' 354 | 355 | method = self.get_method(file) 356 | 357 | params = { 358 | 'recaptcha': 1, 359 | **method, 360 | **kwargs, 361 | } 362 | 363 | result = self.solve(**params) 364 | return result 365 | 366 | def coordinates(self, file, **kwargs): 367 | '''Wrapper for solving coordinates captcha (image). 368 | 369 | Parameters 370 | __________ 371 | file : file 372 | Captcha image file. * required if you submit image as a file (method=post). 373 | body : str 374 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). 375 | hintText : str 376 | Max 140 characters. Endcoding: UTF-8. Text with instruction for solving the captcha. For example: click on 377 | images with ghosts. Not required if the image already contains the instruction. 378 | hintImg : img 379 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending 380 | instruction as text with textinstructions. 381 | lang : str, optional 382 | Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. 383 | callback : str, optional 384 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 385 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 386 | ''' 387 | 388 | method = self.get_method(file) 389 | 390 | params = { 391 | 'coordinatescaptcha': 1, 392 | **method, 393 | **kwargs, 394 | } 395 | 396 | result = self.solve(**params) 397 | return result 398 | 399 | def rotate(self, files, **kwargs): 400 | '''Wrapper for solving rotate captcha (image). 401 | 402 | Parameters 403 | __________ 404 | files : file 405 | Captcha image file. * required if you submit image as a file (method=post). 406 | body : str 407 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). 408 | angle : int, optional 409 | Angle for one rotation step in degrees. If not defined we'll use the default value for FunCaptcha: 40 degrees. 410 | Default: 40. 411 | lang : str, optional 412 | Language code. See the list of supported languages https://solvecaptcha.com/captcha-solver-api#language. 413 | hintImg : str, optional 414 | Image with instruction for worker to help him to solve captcha correctly. 415 | hintText : str, optional 416 | Text will be shown to worker to help him to to solve captcha correctly. 417 | callback : str, optional 418 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 419 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 420 | proxy : dict, optional 421 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. 422 | ''' 423 | 424 | if isinstance(files, str): 425 | 426 | file = self.get_method(files)['file'] 427 | 428 | result = self.solve(file=file, method='rotatecaptcha', **kwargs) 429 | return result 430 | 431 | elif isinstance(files, dict): 432 | files = list(files.values()) 433 | 434 | files = self.extract_files(files) 435 | 436 | result = self.solve(files=files, method='rotatecaptcha', **kwargs) 437 | return result 438 | 439 | def canvas(self, file, **kwargs): 440 | '''Wrapper for solving canvas captcha (image). 441 | 442 | Parameters 443 | __________ 444 | file : file 445 | Captcha image file. * required if you submit image as a file (method=post). 446 | body : str 447 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64). 448 | hintText : str 449 | Max 140 characters. Endcoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select 450 | images with trees. Not required if you're sending instruction as an image with imginstructions. 451 | hintImg : img 452 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending 453 | instruction as text with textinstructions. 454 | canSkip : int, optional 455 | 0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's 456 | possible that there's no images matching to the instruction. We'll provide a button "No matching images" to 457 | worker, and you will receive No_matching_images as answer. 458 | Default: 0. 459 | lang : int, optional 460 | 0 - not specified. 1 - Cyrillic captcha. 2 - Latin captcha. 461 | Default: 0. 462 | callback : str, optional 463 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on 464 | the server. More info here https://solvecaptcha.com/captcha-solver-api#manage_pingback. 465 | ''' 466 | 467 | if not ('hintText' in kwargs or 'hintImg' in kwargs): 468 | raise ValidationException( 469 | 'parameters required: hintText and/or hintImg') 470 | 471 | method = self.get_method(file) 472 | 473 | params = { 474 | 'recaptcha': 1, 475 | 'canvas': 1, 476 | **method, 477 | **kwargs, 478 | } 479 | 480 | result = self.solve(**params) 481 | return result 482 | 483 | def solve(self, timeout=0, polling_interval=0, **kwargs): 484 | '''Sends captcha, receives result. 485 | 486 | Parameters 487 | __________ 488 | timeout : float 489 | 490 | polling_interval : int 491 | 492 | **kwargs : dict 493 | all captcha params 494 | 495 | Returns 496 | 497 | result : string 498 | ''' 499 | 500 | id_ = self.send(**kwargs) 501 | result = {'captchaId': id_} 502 | 503 | if self.callback is None: 504 | timeout = float(timeout or self.default_timeout) 505 | sleep = int(polling_interval or self.polling_interval) 506 | 507 | code = self.wait_result(id_, timeout, sleep) 508 | 509 | if self.extendedResponse == True: 510 | 511 | new_code = { 512 | key if key != 'request' else 'code': value 513 | for key, value in code.items() 514 | if key != 'status' 515 | } 516 | result.update(new_code) 517 | else: 518 | result.update({'code': code}) 519 | 520 | return result 521 | 522 | def wait_result(self, id_, timeout, polling_interval): 523 | 524 | max_wait = time.time() + timeout 525 | 526 | while time.time() < max_wait: 527 | 528 | try: 529 | return self.get_result(id_) 530 | 531 | except NetworkException: 532 | 533 | time.sleep(polling_interval) 534 | 535 | raise TimeoutException(f'timeout {timeout} exceeded') 536 | 537 | def get_method(self, file): 538 | 539 | if not file: 540 | raise ValidationException('File required') 541 | 542 | if not '.' in file and len(file) > 50: 543 | return {'method': 'base64', 'body': file} 544 | 545 | if file.startswith('http'): 546 | img_resp = requests.get(file) 547 | if img_resp.status_code != 200: 548 | raise ValidationException(f'File could not be downloaded from url: {file}') 549 | return {'method': 'base64', 'body': b64encode(img_resp.content).decode('utf-8')} 550 | 551 | if not os.path.exists(file): 552 | raise ValidationException(f'File not found: {file}') 553 | 554 | return {'method': 'post', 'file': file} 555 | 556 | def send(self, **kwargs): 557 | """This method can be used for manual captcha submission 558 | 559 | Parameters 560 | _________ 561 | method : str 562 | The name of the method must be found in the documentation https://solvecaptcha.com/captcha-solver-api 563 | kwargs: dict 564 | All captcha params 565 | Returns 566 | 567 | """ 568 | 569 | params = self.default_params(kwargs) 570 | params = self.rename_params(params) 571 | 572 | params, files = self.check_hint_img(params) 573 | 574 | response = self.api_client.in_(files=files, **params) 575 | 576 | if not response.startswith('OK|'): 577 | raise ApiException(f'cannot recognize response {response}') 578 | 579 | return response[3:] 580 | 581 | def get_result(self, id_): 582 | import json 583 | """This method can be used for manual captcha answer polling. 584 | 585 | Parameters 586 | __________ 587 | id_ : str 588 | ID of the captcha sent for solution 589 | Returns 590 | 591 | answer : text 592 | """ 593 | 594 | if self.extendedResponse == True: 595 | 596 | response = self.api_client.res(key=self.API_KEY, action='get', id=id_, json=1) 597 | 598 | response_data = json.loads(response) 599 | 600 | if response_data.get("status") == 0: 601 | raise NetworkException 602 | 603 | if not response_data.get("status") == 1: 604 | raise ApiException(f'Unexpected status in response: {response_data}') 605 | 606 | return response_data 607 | 608 | else: 609 | 610 | response = self.api_client.res(key=self.API_KEY, action='get', id=id_) 611 | 612 | if response == 'CAPCHA_NOT_READY': 613 | raise NetworkException 614 | 615 | if not response.startswith('OK|'): 616 | raise ApiException(f'cannot recognize response {response}') 617 | 618 | return response[3:] 619 | 620 | def balance(self): 621 | '''Get my balance 622 | 623 | Returns 624 | 625 | balance : float 626 | ''' 627 | 628 | response = self.api_client.res(key=self.API_KEY, action='getbalance') 629 | return float(response) 630 | 631 | def report(self, id_, correct): 632 | '''Report of solved captcha: good/bad. 633 | 634 | Parameters 635 | __________ 636 | id_ : str 637 | captcha ID 638 | 639 | correct : bool 640 | True/False 641 | 642 | Returns 643 | None. 644 | 645 | ''' 646 | 647 | rep = 'reportgood' if correct else 'reportbad' 648 | self.api_client.res(key=self.API_KEY, action=rep, id=id_) 649 | 650 | return 651 | 652 | def rename_params(self, params): 653 | 654 | replace = { 655 | 'caseSensitive': 'regsense', 656 | 'minLen': 'min_len', 657 | 'maxLen': 'max_len', 658 | 'minLength': 'min_len', 659 | 'maxLength': 'max_len', 660 | 'hintText': 'textinstructions', 661 | 'hintImg': 'imginstructions', 662 | 'url': 'pageurl', 663 | 'score': 'min_score', 664 | 'text': 'textcaptcha', 665 | 'rows': 'recaptcharows', 666 | 'cols': 'recaptchacols', 667 | 'previousId': 'previousID', 668 | 'canSkip': 'can_no_answer', 669 | 'apiServer': 'api_server', 670 | 'softId': 'soft_id', 671 | 'callback': 'pingback', 672 | 'datas': 'data-s', 673 | } 674 | 675 | new_params = { 676 | v: params.pop(k) 677 | for k, v in replace.items() if k in params 678 | } 679 | 680 | proxy = params.pop('proxy', '') 681 | proxy and new_params.update({ 682 | 'proxy': proxy['uri'], 683 | 'proxytype': proxy['type'] 684 | }) 685 | 686 | new_params.update(params) 687 | 688 | return new_params 689 | 690 | def default_params(self, params): 691 | 692 | params.update({'key': self.API_KEY}) 693 | 694 | callback = params.pop('callback', self.callback) 695 | soft_id = params.pop('softId', self.soft_id) 696 | 697 | if callback: params.update({'callback': callback}) 698 | if soft_id: params.update({'softId': soft_id}) 699 | 700 | self.has_callback = bool(callback) 701 | 702 | return params 703 | 704 | def extract_files(self, files): 705 | 706 | if len(files) > self.max_files: 707 | raise ValidationException( 708 | f'Too many files (max: {self.max_files})') 709 | 710 | not_exists = [f for f in files if not (os.path.exists(f))] 711 | 712 | if not_exists: 713 | raise ValidationException(f'File not found: {not_exists}') 714 | 715 | files = {f'file_{e+1}': f for e, f in enumerate(files)} 716 | return files 717 | 718 | def check_hint_img(self, params): 719 | 720 | hint = params.pop('imginstructions', None) 721 | files = params.pop('files', {}) 722 | 723 | if not hint: 724 | return params, files 725 | 726 | if not '.' in hint and len(hint) > 50: 727 | params.update({'imginstructions': hint}) 728 | return params, files 729 | 730 | if not os.path.exists(hint): 731 | raise ValidationException(f'File not found: {hint}') 732 | 733 | if not files: 734 | files = {'file': params.pop('file', {})} 735 | 736 | files.update({'imginstructions': hint}) 737 | 738 | return params, files 739 | 740 | 741 | if __name__ == '__main__': 742 | 743 | key = sys.argv[1] 744 | sol = Solvecaptcha(key) 745 | --------------------------------------------------------------------------------