├── .github
└── workflows
│ └── publish-to-pypi.yml
├── .gitignore
├── LICENSE
├── README.md
├── examples
├── amazon_waf.py
├── amazon_waf_options.py
├── atb_captcha.py
├── atb_captcha_options.py
├── audio.py
├── audio
│ └── example.mp3
├── canvas.py
├── canvas_base64.py
├── canvas_options.py
├── capy.py
├── capy_options.py
├── coordinates.py
├── coordinates_base64.py
├── coordinates_options.py
├── cutcaptcha.py
├── cutcaptcha_options.py
├── cybersiara.py
├── datadome.py
├── friendly_captcha.py
├── friendly_captcha_options.py
├── funcaptcha.py
├── funcaptcha_options.py
├── geetest.py
├── geetest_options.py
├── geetest_v4.py
├── geetest_v4_options.py
├── grid.py
├── grid_base64.py
├── grid_options.py
├── images
│ ├── canvas.jpg
│ ├── canvas_hint.jpg
│ ├── grid.jpg
│ ├── grid_2.jpg
│ ├── grid_hint.jpg
│ ├── normal.jpg
│ ├── normal_2.jpg
│ └── rotate.jpg
├── keycaptcha.py
├── keycaptcha_options.py
├── lemin.py
├── mtcaptcha.py
├── mtcaptcha_options.py
├── normal.py
├── normal_base64.py
├── normal_options.py
├── recaptcha_v2.py
├── recaptcha_v2_options.py
├── recaptcha_v3.py
├── recaptcha_v3_options.py
├── rotate.py
├── rotate_options.py
├── tencent.py
├── tencent_options.py
├── text.py
├── text_options.py
├── turnstile.py
├── turnstile_options.py
├── yandex_smart.py
└── yandex_smart_options.py
├── requirements.txt
├── setup.py
├── tests
├── abstract.py
├── canvas_test.py
├── test_amazon_waf.py
├── test_atb_captcha.py
├── test_canvas.py
├── test_capy.py
├── test_coordinates.py
├── test_cutcaptcha.py
├── test_cybersiara.py
├── test_datadome.py
├── test_friendly_captcha.py
├── test_funcaptcha.py
├── test_geetest.py
├── test_geetest_v4.py
├── test_grid.py
├── test_hcaptcha.py
├── test_keycaptcha.py
├── test_lemin.py
├── test_mtcaptcha.py
├── test_normal.py
├── test_recaptcha.py
├── test_rotate.py
├── test_tencent.py
├── test_text.py
├── test_turnstile.py
└── test_yandex_smart_captcha.py
└── twocaptcha
├── __init__.py
├── api.py
└── solver.py
/.github/workflows/publish-to-pypi.yml:
--------------------------------------------------------------------------------
1 | name: Publish to PyPI
2 | on: push
3 | jobs:
4 | build-n-publish:
5 | name: Build and publish to PyPI
6 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@master
10 | - name: Set up Python 3.10
11 | uses: actions/setup-python@v3
12 | with:
13 | python-version: "3.10"
14 | - name: Install pypa/build
15 | run: >-
16 | python -m
17 | pip install
18 | build
19 | --user
20 | - name: Build a binary wheel and a source tarball
21 | run: >-
22 | python -m
23 | build
24 | --sdist
25 | --wheel
26 | --outdir dist/
27 | .
28 | - name: Publish to Test PyPI
29 | continue-on-error: true
30 | uses: pypa/gh-action-pypi-publish@release/v1
31 | with:
32 | password: ${{ secrets.TEST_PYPI_API_TOKEN }}
33 | repository_url: https://test.pypi.org/legacy/
34 | - name: Publish to PyPI
35 | if: startsWith(github.ref, 'refs/tags')
36 | uses: pypa/gh-action-pypi-publish@release/v1
37 | with:
38 | password: ${{ secrets.PYPI_API_TOKEN }}
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
98 | __pypackages__/
99 |
100 | # Celery stuff
101 | celerybeat-schedule
102 | celerybeat.pid
103 |
104 | # SageMath parsed files
105 | *.sage.py
106 |
107 | # Environments
108 | .env
109 | .venv
110 | env/
111 | venv/
112 | ENV/
113 | env.bak/
114 | venv.bak/
115 |
116 | # Spyder project settings
117 | .spyderproject
118 | .spyproject
119 |
120 | # Rope project settings
121 | .ropeproject
122 |
123 | # mkdocs documentation
124 | /site
125 |
126 | # mypy
127 | .mypy_cache/
128 | .dmypy.json
129 | dmypy.json
130 |
131 | # Pyre type checker
132 | .pyre/
133 |
134 | # pytype static type analyzer
135 | .pytype/
136 |
137 | # Cython debug symbols
138 | cython_debug/
139 |
140 | .vscode/
141 | .idea/
142 | .DS_Store
143 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 2captcha
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | # Python Module for 2Captcha API (captcha solver)
11 |
12 | The easiest way to quickly integrate the [2Captcha] captcha-solving service into your code and automate the solving of any type of captcha.
13 | Examples of API requests for different captcha types are available on the [Python captcha solver](https://2captcha.com/lang/python) page.
14 |
15 | - [Python Module for 2Captcha API (captcha solver)](#python-module-for-2captcha-api-captcha-solver)
16 | - [Installation](#installation)
17 | - [Configuration](#configuration)
18 | - [TwoCaptcha instance options](#twocaptcha-instance-options)
19 | - [Solve captcha](#solve-captcha)
20 | - [Captcha options](#captcha-options)
21 | - [Normal Captcha](#normal-captcha)
22 | - [Audio Captcha](#audio-captcha)
23 | - [Text Captcha](#text-captcha)
24 | - [reCAPTCHA v2](#recaptcha-v2)
25 | - [reCAPTCHA v3](#recaptcha-v3)
26 | - [FunCaptcha](#funcaptcha)
27 | - [GeeTest](#geetest)
28 | - [GeeTest v4](#geetest-v4)
29 | - [Yandex Smart](#yandex-smart)
30 | - [Lemin Cropped Captcha](#lemin-cropped-captcha)
31 | - [Cloudflare Turnstile](#cloudflare-turnstile)
32 | - [Amazon WAF](#amazon-waf)
33 | - [KeyCaptcha](#keycaptcha)
34 | - [atbCAPTCHA](#atbcaptcha)
35 | - [Capy](#capy)
36 | - [Grid](#grid)
37 | - [Canvas](#canvas)
38 | - [ClickCaptcha](#clickcaptcha)
39 | - [Rotate](#rotate)
40 | - [MTCaptcha](#mtcaptcha)
41 | - [Friendly Captcha](#friendly-captcha)
42 | - [Cutcaptcha](#cutcaptcha)
43 | - [Tencent](#tencent)
44 | - [DataDome](#datadome)
45 | - [CyberSiARA](#cybersiara)
46 | - [Other methods](#other-methods)
47 | - [send / get\_result](#send--get_result)
48 | - [balance](#balance)
49 | - [report](#report)
50 | - [Error handling](#error-handling)
51 | - [Proxies](#proxies)
52 | - [Async calls](#async-calls)
53 | - [Examples](#examples)
54 | - [Examples using Selenium](#examples-using-selenium)
55 | - [Useful articles](#useful-articles)
56 | - [Get in touch](#get-in-touch)
57 | - [Join the team 👪](#join-the-team-)
58 | - [License](#license)
59 | - [Graphics and Trademarks](#graphics-and-trademarks)
60 |
61 | ## Installation
62 |
63 | This package can be installed with Pip:
64 |
65 | ```bash
66 | pip3 install 2captcha-python
67 | ```
68 |
69 |
70 | ## Configuration
71 |
72 | TwoCaptcha instance can be created like this:
73 |
74 | ```python
75 | from twocaptcha import TwoCaptcha
76 |
77 | solver = TwoCaptcha('YOUR_API_KEY')
78 | ```
79 | Also, there are a few options that can be configured:
80 |
81 | ```python
82 | config = {
83 | 'server': '2captcha.com',
84 | 'apiKey': 'YOUR_API_KEY',
85 | 'softId': 123,
86 | 'callback': 'https://your.site/result-receiver',
87 | 'defaultTimeout': 120,
88 | 'recaptchaTimeout': 600,
89 | 'pollingInterval': 10,
90 | 'extendedResponse': False
91 | }
92 | solver = TwoCaptcha(**config)
93 | ```
94 |
95 | ### TwoCaptcha instance options
96 |
97 | | Option | Default value | Description |
98 | | ---------------- | -------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------|
99 | | server | `2captcha.com` | API server. You can set it to `rucaptcha.com` if your account is registered there |
100 | | softId | 4580 | your software ID obtained after publishing in [2captcha software catalog] |
101 | | callback | - | URL of your web server that receives the captcha recognition result. The URL should be first registered in [pingback settings] of your account |
102 | | defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from the `res.php` API endpoint |
103 | | recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from the `res.php` API endpoint |
104 | | pollingInterval | 10 | Interval in seconds between requests to the `res.php` API endpoint. Setting values less than 5 seconds is not recommended |
105 | | extendedResponse | None | Set to `True` to get the response with additional fields or in more practical format (enables `JSON` response from `res.php` API endpoint). Suitable for [ClickCaptcha](#clickcaptcha), [Canvas](#canvas) |
106 |
107 |
108 | > [!IMPORTANT]
109 | > Once `callback` is defined for the `TwoCaptcha` 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.
110 |
111 | To get the answer manually use [get_result method](#send--get_result)
112 |
113 | ## Solve captcha
114 | When you submit any image-based CAPTCHA, you can provide additional options to help 2captcha workers solve it properly.
115 |
116 | ### Captcha options
117 | | Option | Default Value | Description |
118 | | ------------- | ------------- | -------------------------------------------------------------------------------------------------- |
119 | | numeric | 0 | Defines if the captcha contains numeric or other symbols [see more info in the API docs][post options] |
120 | | minLen | 0 | minimal answer length |
121 | | maxLen | 0 | maximum answer length |
122 | | phrase | 0 | defines if the answer contains multiple words or not |
123 | | caseSensitive | 0 | defines if the answer is case sensitive |
124 | | calc | 0 | defines captcha requires calculation |
125 | | lang | - | defines the captcha language; see the [list of supported languages] |
126 | | hintImg | - | an image with a hint shown to workers with the captcha |
127 | | hintText | - | hint or task text shown to workers with the captcha |
128 |
129 | Below, you can find basic examples for every captcha type. Check out [examples directory] for more examples with all available options.
130 |
131 | ### Normal Captcha
132 |
133 | [API method description.](https://2captcha.com/2captcha-api#solving_normal_captcha)
134 |
135 | To bypass a normal captcha (distorted text on an image) use the following method. This method can also be used to recognize any text in an image.
136 |
137 | ```python
138 | result = solver.normal('path/to/captcha.jpg', param1=..., ...)
139 | # OR
140 | result = solver.normal('https://site-with-captcha.com/path/to/captcha.jpg', param1=..., ...)
141 | ```
142 |
143 | ### Audio Captcha
144 |
145 | [API method description.](https://2captcha.com/2captcha-api#audio)
146 |
147 | Use the following method to bypass an audio captcha (mp3 formats only).
148 | You must provide the language as `lang = 'en'`. Supported languages are "en", "ru", "de", "el", "pt", "fr".
149 |
150 | ```python
151 | result = solver.audio('path/to/captcha.mp3', lang = 'lang', param1=..., ...)
152 | # OR
153 | result = solver.audio('https://site-with-captcha.com/path/to/captcha.mp3', lang = 'lang', param1=..., ...)
154 | ```
155 |
156 | ### Text Captcha
157 |
158 | [API method description.](https://2captcha.com/2captcha-api#solving_text_captcha)
159 |
160 | This method can be used to bypass a captcha that requires answering a question provided in clear text.
161 | ```python
162 | result = solver.text('If tomorrow is Saturday, what day is today?', param1=..., ...)
163 | ```
164 |
165 | ### reCAPTCHA v2
166 |
167 | [API method description.](https://2captcha.com/2captcha-api#solving_recaptchav2_new)
168 |
169 | Use the following method to solve reCAPTCHA V2 and obtain a token to bypass the protection.
170 |
171 | ```python
172 | result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
173 | url='https://mysite.com/page/with/recaptcha',
174 | param1=..., ...)
175 | ```
176 |
177 | ### reCAPTCHA v3
178 |
179 | [API method description.](https://2captcha.com/2captcha-api#solving_recaptchav3)
180 |
181 | This method provides a reCAPTCHA V3 solver and returns a token.
182 | ```python
183 | result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
184 | url='https://mysite.com/page/with/recaptcha',
185 | version='v3',
186 | param1=..., ...)
187 | ```
188 |
189 | ### FunCaptcha
190 |
191 | [API method description.](https://2captcha.com/2captcha-api#solving_funcaptcha_new)
192 |
193 | FunCaptcha (Arkoselabs) solving method. Returns a token.
194 | ```python
195 | result = solver.funcaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
196 | url='https://mysite.com/page/with/funcaptcha',
197 | param1=..., ...)
198 |
199 | ```
200 |
201 |
202 | ### GeeTest
203 |
204 | [API method description.](https://2captcha.com/2captcha-api#solving_geetest)
205 |
206 | Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.
207 | ```python
208 | result = solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e',
209 | challenge='12345678abc90123d45678ef90123a456b',
210 | url='https://www.site.com/page/',
211 | param1=..., ...)
212 |
213 | ```
214 |
215 |
216 | ### GeeTest v4
217 |
218 | [API method description.](https://2captcha.com/2captcha-api#geetest-v4)
219 |
220 | Use this method to solve GeeTest v4. Returns the response in JSON.
221 | ```python
222 | result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
223 | url='https://www.site.com/page/',
224 | param1=..., ...)
225 |
226 | ```
227 |
228 |
229 | ### Lemin Cropped Captcha
230 |
231 | [API method description.](https://2captcha.com/2captcha-api#lemin)
232 |
233 | Use this method to solve the Lemin captcha. Returns JSON with an answer containing the following values: answer, challenge_id.
234 | ```python
235 | result = solver.lemin(captcha_id='CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',
236 | div_id='lemin-cropped-captcha',
237 | url='https://www.site.com/page/',
238 | param1=..., ...)
239 |
240 | ```
241 |
242 | ### Yandex Smart
243 |
244 | Use this method to solve Yandex Smart Captcha. Returns JSON with the token.
245 | ```python
246 | result = solver.yandex_smart(sitekey='0x1AAAAh45AAAAkg0s2VIOD34y5hy4h4h',
247 | url='http://mysite.com/',
248 | proxy={'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'},
249 | 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')
250 | ```
251 |
252 | ### Cloudflare Turnstile
253 |
254 | [API method description.](https://2captcha.com/2captcha-api#turnstile)
255 |
256 | Use this method to solve Cloudflare Turnstile. Returns JSON with the token.
257 | ```python
258 | result = solver.turnstile(sitekey='0x1AAAAAAAAkg0s2VIOD34y5',
259 | url='http://mysite.com/',
260 | data='foo',
261 | pagedata='bar',
262 | action='challenge',
263 | 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')
264 | ```
265 |
266 | ### Amazon WAF
267 |
268 | [API method description.](https://2captcha.com/2captcha-api#amazon-waf)
269 |
270 | Use this method to solve Amazon WAF Captcha also known as AWS WAF Captcha is a part of Intelligent threat mitigation for Amazon AWS. Returns JSON with the token.
271 | ```python
272 | result = solver.amazon_waf(sitekey='0x1AAAAAAAAkg0s2VIOD34y5',
273 | iv='CgAHbCe2GgAAAAAj',
274 | context='9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb+sUNLoukWedAQZKrlY4RdbOOzvcFqmD/ZepQFS9N5w15Exr4VwnVq+HIxTsDJwRviElWCdzKDebN/mk8/eX2n7qJi5G3Riq0tdQw9+C4diFZU5E97RSeahejOAAJTDqduqW6uLw9NsjJBkDRBlRjxjn5CaMMo5pYOxYbGrM8Un1JH5DMOLeXbq1xWbC17YSEoM1cRFfTgOoc+VpCe36Ai9Kc='
275 | url='https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest'
276 | param1=..., ...)
277 |
278 | ```
279 |
280 |
281 | ### KeyCaptcha
282 |
283 | [API method description.](https://2captcha.com/2captcha-api#solving_keycaptcha)
284 |
285 | Token-based method to solve KeyCaptcha.
286 | ```python
287 | result = solver.keycaptcha(s_s_c_user_id=10,
288 | s_s_c_session_id='493e52c37c10c2bcdf4a00cbc9ccd1e8',
289 | s_s_c_web_server_sign='9006dc725760858e4c0715b835472f22-pz-',
290 | s_s_c_web_server_sign2='2ca3abe86d90c6142d5571db98af6714',
291 | url='https://www.keycaptcha.ru/demo-magnetic/',
292 | param1=..., ...)
293 |
294 | ```
295 |
296 |
297 | ### atbCAPTCHA
298 |
299 | [API method description.](https://2captcha.com/2captcha-api#atb-captcha)
300 |
301 | Use this method to solve atbCaptcha challenge. Returns a token to bypass the captcha.
302 | ```python
303 | result = solver.atb_captcha(app_id='af25e409b33d722a95e56a230ff8771c',
304 | api_server='https://cap.aisecurius.com',
305 | url='http://mysite.com/',
306 | param1=..., ...)
307 |
308 | ```
309 |
310 |
311 | ### Capy
312 |
313 | [API method description.](https://2captcha.com/2captcha-api#solving_capy)
314 |
315 | Token-based method to bypass Capy puzzle captcha.
316 | ```python
317 | result = solver.capy(sitekey='PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
318 | url='http://mysite.com/',
319 | api_server='https://jp.api.capy.me/',
320 | param1=..., ...)
321 | ```
322 | ### Grid
323 |
324 | [API method description.](https://2captcha.com/2captcha-api#grid)
325 |
326 | The grid method was originally called the Old reCAPTCHA V2 method. The method can be used to bypass any type of captcha where you can apply a grid on an image and click specific grid boxes. Returns numbers of boxes.
327 |
328 | ```python
329 | result = solver.grid('path/to/captcha.jpg', param1=..., ...)
330 | ```
331 |
332 | ### Canvas
333 |
334 | [API method description.](https://2captcha.com/2captcha-api#canvas)
335 |
336 | The canvas method can be used when you need to draw a line around an object on an image. Returns a set of points' coordinates to draw a polygon.
337 |
338 | ```python
339 | result = solver.canvas('path/to/captcha.jpg', param1=..., ...)
340 | ```
341 |
342 | ### ClickCaptcha
343 |
344 | [API method description.](https://2captcha.com/2captcha-api#coordinates)
345 |
346 | The ClickCaptcha method returns the coordinates of points on the captcha image. It can be used if you need to click on particular points in the image.
347 |
348 | ```python
349 | result = solver.coordinates('path/to/captcha.jpg', param1=..., ...)
350 | ```
351 |
352 | ### Rotate
353 |
354 | [API method description.](https://2captcha.com/2captcha-api#solving_rotatecaptcha)
355 |
356 | This method can be used to solve a captcha that asks to rotate an object. It is mostly used to bypass FunCaptcha. Returns the rotation angle.
357 |
358 | ```python
359 | result = solver.rotate('path/to/captcha.jpg', param1=..., ...)
360 | ```
361 |
362 | ### MTCaptcha
363 |
364 | [API method description.](https://2captcha.com/2captcha-api#mtcaptcha)
365 |
366 | Use this method to solve MTCaptcha and obtain a token to bypass the protection.
367 | ```python
368 | result = solver.mtcaptcha(sitekey='MTPublic-KzqLY1cKH',
369 | url='https://2captcha.com/demo/mtcaptcha',
370 | param1=..., ...)
371 | ```
372 |
373 | ### Friendly Captcha
374 |
375 | [API method description.](https://2captcha.com/2captcha-api#friendly-captcha)
376 |
377 | Friendly Captcha solving method. Returns a token.
378 |
379 | > [!IMPORTANT]
380 | > To successfully use the received token, the captcha widget must not be loaded on the page. To do this, you need to abort request to `/friendlycaptcha/...module.min.js` on the page. When the captcha widget is already loaded on the page, there is a high probability that the received token will not work.
381 |
382 | ```python
383 | result = solver.friendly_captcha(sitekey='FCMGEMUD2KTDSQ5H',
384 | url='https://friendlycaptcha.com/demo',
385 | param1=..., ...)
386 | ```
387 |
388 | ### Cutcaptcha
389 |
390 | [API method description.](https://2captcha.com/2captcha-api#cutcaptcha)
391 |
392 | Use this method to solve Cutcaptcha. Returns the response in JSON.
393 | ```python
394 | result = solver.cutcaptcha(misery_key='ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
395 | apikey='SAs61IAI',
396 | url='https://mysite.com/page/with/cutcaptcha',
397 | param1=..., ...)
398 | ```
399 |
400 | ### Tencent
401 |
402 | [API method description.](https://2captcha.com/2captcha-api#tencent)
403 |
404 | Use this method to solve Tencent captcha. Returns a token.
405 | ```python
406 | result = solver.tencent(app_id="197326679",
407 | url="https://mysite.com/page/with/tencent",
408 | param1=..., ...)
409 | ```
410 |
411 | ### DataDome
412 |
413 | [API method description.](https://2captcha.com/2captcha-api#datadome)
414 |
415 | Use this method to solve DataDome captcha.
416 |
417 | > [!IMPORTANT]
418 | > To solve the DataDome captcha, you must use a proxy. It is recommended to use [residential proxies].
419 |
420 | ```python
421 | result = solver.datadome(captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=...",
422 | pageurl="https://mysite.com/page/with/datadome",
423 | userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
424 | proxy={
425 | 'type': 'HTTP',
426 | 'uri': 'login:password@IP_address:PORT'
427 | },
428 | param1=..., ...)
429 | ```
430 |
431 | ### CyberSiARA
432 |
433 | [API method description.](https://2captcha.com/2captcha-api#cybersiara)
434 |
435 | Use this method to solve CyberSiARA. Returns a token.
436 | ```python
437 | result = solver.cybersiara(master_url_id='tpjOCKjjpdzv3d8Ub2E9COEWKt1vl1Mv',
438 | pageurl='https://demo.mycybersiara.com/',
439 | userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
440 | param1=..., ...)
441 | ```
442 |
443 | ## Other methods
444 |
445 | ### send / get_result
446 | These methods can be used for manual captcha submission and answer polling. The `send()` method supports sending any captcha
447 | type, to specify the captcha type you must send value `method` manually, for example `method='recaptcha'` for solving reCaptcha.
448 | You can find the value of the `method` parameter in the [API documentation](https://2captcha.com/2captcha-api).
449 |
450 | Example for solving Normal captcha manually:
451 | ```python
452 | import time
453 | . . . . .
454 |
455 |
456 | id = solver.send(file='path/to/captcha.jpg')
457 | time.sleep(20)
458 |
459 | code = solver.get_result(id)
460 | ```
461 |
462 | ### balance
463 |
464 | [API method description.](https://2captcha.com/2captcha-api#additional-methods)
465 |
466 | Use this method to get your account's balance
467 | ```python
468 | balance = solver.balance()
469 | ```
470 |
471 | ### report
472 |
473 | [API method description.](https://2captcha.com/2captcha-api#complain)
474 |
475 | Use this method to report good or bad captcha answers.
476 | ```python
477 | solver.report(id, True) # captcha solved correctly
478 | solver.report(id, False) # captcha solved incorrectly
479 | ```
480 |
481 | ## Error handling
482 | In case of an error, the captcha solver throws an exception. It's important to properly handle these cases. We recommend using `try except` to handle exceptions.
483 | The list of all errors can be found in the [API documentation](https://2captcha.com/2captcha-api#list-of-inphp-errors).
484 | ```python
485 | try:
486 | result = solver.text('If tomorrow is Saturday, what day is today?')
487 | except ValidationException as e:
488 | # invalid parameters passed
489 | print(e)
490 | except NetworkException as e:
491 | # network error occurred
492 | print(e)
493 | except ApiException as e:
494 | # api respond with error
495 | print(e)
496 | except TimeoutException as e:
497 | # captcha is not solved so far
498 | print(e)
499 | ```
500 |
501 |
502 | ## Proxies
503 |
504 | You can pass your proxy as an additional argument for the following methods: recaptcha, funcaptcha, geetest, geetest v4,
505 | keycaptcha, capy puzzle, lemin, atbcaptcha, turnstile, amazon waf, mtcaptcha, friendly captcha, cutcaptcha, Tencent, DataDome, cybersiara.
506 |
507 |
508 | The proxy will be forwarded to the API to solve the captcha.
509 |
510 | We have our own proxies that we can offer you. [Buy residential proxies] to avoid restrictions and blocks. [Quick start].
511 |
512 | ```python
513 | proxy={
514 | 'type': 'HTTPS',
515 | 'uri': 'login:password@IP_address:PORT'
516 | }
517 | ```
518 |
519 | ## Async calls
520 | You can also make async calls with [asyncio], for example:
521 |
522 | ```python
523 | import asyncio
524 | import concurrent.futures
525 | from twocaptcha import TwoCaptcha
526 |
527 | API_KEY = "YOUR_API_KEY"
528 | image = "data:image/png;base64,iVBORw0KGgoA..."
529 |
530 | async def captchaSolver(image):
531 | loop = asyncio.get_running_loop()
532 | with concurrent.futures.ThreadPoolExecutor() as pool:
533 | result = await loop.run_in_executor(pool, lambda: TwoCaptcha(API_KEY).normal(image))
534 | return result
535 |
536 | captcha_result = asyncio.run(captchaSolver(image))
537 | ```
538 | ## Examples
539 | Examples of solving all supported captcha types are located in the [examples] directory.
540 |
541 | ## Examples using Selenium
542 | Also we have a [separate repository](https://github.com/2captcha/captcha-solver-selenium-python-examples) you can find examples of captcha solving using [Selenium](https://pypi.org/project/selenium/) library. At the moment we have implemented examples of bypassing [reCAPTCHA](https://github.com/2captcha/captcha-solver-selenium-python-examples/tree/main/examples/reCAPTCHA), [Cloudflare](https://github.com/2captcha/captcha-solver-selenium-python-examples/tree/main/examples/cloudflare), [Coordinates](https://github.com/2captcha/captcha-solver-selenium-python-examples/tree/main/examples/coordinates), [MTCaptcha](https://github.com/2captcha/captcha-solver-selenium-python-examples/tree/main/examples/mtcaptcha), [normal captcha](https://github.com/2captcha/captcha-solver-selenium-python-examples/tree/main/examples/normal_captcha) (image captcha) and [text captcha](https://github.com/2captcha/captcha-solver-selenium-python-examples/tree/main/examples/text_captcha) using Selenium.
543 |
544 | ## Useful articles
545 |
546 | - Amazon captcha solver: Code example for bypassing the [Amazon captcha](https://2captcha.com/blog/amazon-captcha-solving)
547 | - [Captcha bypass in Selenium](https://2captcha.com/blog/captcha-bypass-in-selenium)
548 |
549 | ## Get in touch
550 |
551 |
552 |
553 |
554 | ## Join the team 👪
555 |
556 | There are many ways to contribute, of which development is only one! Find your next job. Open positions: AI experts, scrapers, developers, technical support, and much more! 😍
557 |
558 |
559 |
560 |
561 | ## License
562 |
563 | The code in this repository is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.
564 |
565 | ### Graphics and Trademarks
566 |
567 | The graphics and trademarks included in this repository are not covered by the MIT License. Please contact support for permissions regarding the use of these materials.
568 |
569 |
570 |
571 | [2Captcha]: https://2captcha.com/
572 | [2captcha software catalog]: https://2captcha.com/software
573 | [pingback settings]: https://2captcha.com/setting/pingback
574 | [post options]: https://2captcha.com/2captcha-api#normal_post
575 | [list of supported languages]: https://2captcha.com/2captcha-api#language
576 | [examples directory]: /examples
577 | [asyncio]: https://docs.python.org/3/library/asyncio.html
578 | [Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
579 | [Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true
580 | [examples]: ./examples
581 | [residential proxies]: https://2captcha.com/proxy/residential-proxies
582 |
--------------------------------------------------------------------------------
/examples/amazon_waf.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | """
19 | Important: the values of the 'iv' and 'context' parameters are dynamic, for every request to our API you need to get new values.
20 | The values 'iv' and 'context' need to be looked for in the page code.
21 | """
22 |
23 | try:
24 | result = solver.amazon_waf(
25 | sitekey='AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AFsClhVgr5q0UFRdXhhHEwiAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMLMbH8d6uQSrYTraoAgEQgDvtSNxdEyG7Zu393cHyPdWNCZgeIB52+W7fCTI8U5z15z1NdPUdnB1ZHoK7ewpwoSMm5mzkJJld0cnvGw==',
26 | iv='CgAAYDJb9CAAACAq',
27 | context='wCho9T9OcETTT8fu1k6+rszr5aGt4eLd+K3mHpV8VbSkjAWJGJx/iQ16RKDCTQBtU5OSeE+SQqoS5iTzhgGtvwgmBbr7X/I+aXaNfb2JRZ8eJ7CnQpM9QRwnv7vGgrGRBGhkh/jaVYmXdy0j0x21s3dCBlA4VN3naDHIweZqkyhXqJBNI1Ep8OMSnhXtPebboB117aBW4IU4XEOii8EE1G4Z7ndWhrNVVXYYwVoxfnSqfYX//CJir6dZfLMbCt5t7NnO8yjsx/YHGVXFVBt2Zrj0ZTxowoYbHU/BKyFaXgUj+ZQ=',
28 | url='https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest',
29 | )
30 |
31 | except Exception as e:
32 | sys.exit(e)
33 |
34 | else:
35 | sys.exit('result: ' + str(result))
36 |
--------------------------------------------------------------------------------
/examples/amazon_waf_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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | """
30 | Important: the values of the 'iv' and 'context' parameters are dynamic, for every request to our API you need to get new values.
31 | The values 'iv' and 'context' need to be looked for in the page code.
32 | """
33 |
34 | try:
35 | result = solver.amazon_waf(sitekey='AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AGIqvS8v6ScFa8ZpNRrlQgKAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMx9gxoe10Zg35PWhzAgEQgDvUtMMkqkFQByMLK2329D8iX4mjvaTuUhU70LD4vLp54v3+4K1nYY2hB+OM1hMbncnMbP63y4UOrY77jg==',
36 | iv='CgAGVTNd9JAAAAnB',
37 | context='Lte3LdSjiAN6nNcV0omaNt/ydFmd/eTwRCxYEeuW97LZe3IbAXWi4Er9CWQ3HbDgJ0KSpDgwyoskjKCK4VRQzYufPCdrfCYCveZCt9pMNoAluEtj0oix2GXOPVkw2d4bYOg3MtY5ZUHLR3L467NEInnRE99w5NOgokH5Ie7eOi5sYAqYtZrHABGEgrdAOVvU7bcwvrCERi9wB/WS75geb3oFy6z7Apue9GFa86Ld20jjgy4LWfaen+2fpfKHmCHTKVWfto17Bg+l5i0sr+uFRzpk1We64Fhh1Wl1NHF6M6dpS5s=',
38 | url='https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest',
39 | challenge_script="https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js",
40 | captcha_script="https://41bcdd4fb3cb.610cd090.us-east-1.captcha.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/captcha.js",
41 | callback="https://mysite.com/2captcha.txt"
42 | # proxy={
43 | # 'type': 'HTTPS',
44 | # 'uri': 'login:password@IP_address:PORT'
45 | # }
46 | )
47 |
48 | except Exception as e:
49 | sys.exit(e)
50 |
51 | else:
52 | sys.exit('result: ' + str(result))
53 |
--------------------------------------------------------------------------------
/examples/atb_captcha.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.atb_captcha(
20 | app_id='af25e409b33d722a95e56a230ff8771c',
21 | api_server='https://cap.aisecurius.com',
22 | url='http://mysite.com/',
23 | )
24 |
25 | except Exception as e:
26 | sys.exit(e)
27 |
28 | else:
29 | sys.exit('result: ' + str(result))
30 |
--------------------------------------------------------------------------------
/examples/atb_captcha_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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | try:
30 | result = solver.atb_captcha(app_id='af25e409b33d722a95e56a230ff8771c',
31 | api_server='https://cap.aisecurius.com',
32 | url='http://mysite.com/',
33 | # proxy={
34 | # 'type': 'HTTPS',
35 | # 'uri': 'login:password@IP_address:PORT'
36 | # }
37 | )
38 |
39 | except Exception as e:
40 | sys.exit(e)
41 |
42 | else:
43 | sys.exit('result: ' + str(result))
44 |
--------------------------------------------------------------------------------
/examples/audio.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.audio('./audio/example.mp3', lang='en')
20 |
21 | except Exception as e:
22 | sys.exit(e)
23 |
24 | else:
25 | sys.exit('result: ' + str(result))
26 |
--------------------------------------------------------------------------------
/examples/audio/example.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/audio/example.mp3
--------------------------------------------------------------------------------
/examples/canvas.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
4 | from twocaptcha import TwoCaptcha
5 |
6 | # in this example we store the API key inside environment variables that can be set like:
7 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
8 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
9 | # you can just set the API key directly to it's value like:
10 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
11 |
12 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
13 |
14 | solver = TwoCaptcha(api_key)
15 |
16 | try:
17 | result = solver.canvas('./images/canvas.jpg', hintText='Draw around apple')
18 |
19 | except Exception as e:
20 | sys.exit(e)
21 |
22 | else:
23 | sys.exit('result: ' + str(result))
24 |
--------------------------------------------------------------------------------
/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 | from twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | with open('./images/canvas.jpg', 'rb') as f:
19 | b64 = b64encode(f.read()).decode('utf-8')
20 |
21 | try:
22 | result = solver.canvas(b64, hintText='Draw around apple')
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
29 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
6 |
7 | # in this example we store the API key inside environment variables that can be set like:
8 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10 | # you can just set the API key directly to it's value like:
11 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
12 |
13 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14 |
15 | solver = TwoCaptcha(api_key, defaultTimeout=120, pollingInterval=5, server='2captcha.com')
16 |
17 | try:
18 | result = solver.canvas(
19 | './images/canvas.jpg',
20 | previousId=0,
21 | canSkip=0,
22 | lang='en',
23 | hintImg='./images/canvas_hint.jpg',
24 | hintText='Draw around apple',
25 | )
26 |
27 | except Exception as e:
28 | sys.exit(e)
29 |
30 | else:
31 | sys.exit('result: ' + str(result))
32 |
--------------------------------------------------------------------------------
/examples/capy.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
4 |
5 | from twocaptcha import TwoCaptcha
6 |
7 | # in this example we store the API key inside environment variables that can be set like:
8 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10 | # you can just set the API key directly to it's value like:
11 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
12 |
13 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14 |
15 | solver = TwoCaptcha(api_key)
16 |
17 | try:
18 | result = solver.capy(
19 | sitekey='PUZZLE_Cz04hZLjuZRMYC3ee10C32D3uNms5w',
20 | url='https://www.mysite.com/page/captcha/',
21 | api_server="https://jp.api.capy.me/",
22 | )
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
29 |
--------------------------------------------------------------------------------
/examples/capy_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 twocaptcha import TwoCaptcha
6 |
7 | # in this example we store the API key inside environment variables that can be set like:
8 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10 | # you can just set the API key directly to it's value like:
11 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
12 |
13 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14 |
15 | solver = TwoCaptcha(api_key, defaultTimeout=30, pollingInterval=5)
16 |
17 | try:
18 | result = solver.capy(sitekey='PUZZLE_Cz04hZLjuZRMYC3ee10C32D3uNms5w',
19 | url='https://www.mysite.com/captcha/',
20 | api_server="https://jp.api.capy.me/",
21 | softId=33112)
22 |
23 | except Exception as e:
24 | sys.exit(e)
25 |
26 | else:
27 | sys.exit('result: ' + str(result))
28 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
6 |
7 | # in this example we store the API key inside environment variables that can be set like:
8 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10 | # you can just set the API key directly to it's value like:
11 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
12 |
13 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14 |
15 | solver = TwoCaptcha(api_key)
16 |
17 | try:
18 | result = solver.coordinates('./images/grid.jpg')
19 |
20 | except Exception as e:
21 | sys.exit(e)
22 |
23 | else:
24 | sys.exit('result: ' + str(result))
25 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
8 |
9 | # in this example we store the API key inside environment variables that can be set like:
10 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12 | # you can just set the API key directly to it's value like:
13 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
14 |
15 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16 |
17 | solver = TwoCaptcha(api_key)
18 |
19 | with open('./images/grid.jpg', 'rb') as f:
20 | b64 = b64encode(f.read()).decode('utf-8')
21 |
22 | try:
23 | result = solver.coordinates(b64)
24 |
25 | except Exception as e:
26 | sys.exit(e)
27 |
28 | else:
29 | sys.exit('result: ' + str(result))
30 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key, defaultTimeout=120, pollingInterval=5, extendedResponse=True)
17 |
18 | try:
19 | result = solver.coordinates('./images/grid_2.jpg',
20 | lang='en',
21 | hintImg='./images/grid_hint.jpg',
22 | hintText='Select all images with an Orange',
23 | min_clicks=2,
24 | max_clicks=3)
25 | except Exception as e:
26 | sys.exit(e)
27 |
28 | else:
29 | sys.exit('result: ' + str(result))
30 |
--------------------------------------------------------------------------------
/examples/cutcaptcha.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | solver = TwoCaptcha(api_key)
18 |
19 | try:
20 | result = solver.cutcaptcha(
21 | misery_key='ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
22 | apikey='SAs61IAI',
23 | url='https://mysite.com/page/with/cutcaptcha',
24 | )
25 |
26 | except Exception as e:
27 | sys.exit(e)
28 |
29 | else:
30 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/examples/cutcaptcha_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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | config = {
17 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18 | 'apiKey': api_key,
19 | 'softId': 123,
20 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21 | 'defaultTimeout': 120,
22 | 'recaptchaTimeout': 600,
23 | 'pollingInterval': 10,
24 | }
25 |
26 | solver = TwoCaptcha(**config)
27 |
28 | try:
29 | result = solver.cutcaptcha(misery_key='ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
30 | apikey='SAs61IAI',
31 | url='https://mysite.com/page/with/cutcaptcha'
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))
--------------------------------------------------------------------------------
/examples/cybersiara.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | solver = TwoCaptcha(api_key)
18 |
19 | try:
20 | result = solver.cybersiara(
21 | master_url_id='tpjOCKjjpdzv3d8Ub2E9COEWKt1vl1Mv',
22 | pageurl='https://demo.mycybersiara.com/',
23 | userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
24 | )
25 |
26 | except Exception as e:
27 | sys.exit(e)
28 |
29 | else:
30 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/examples/datadome.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | import json
4 |
5 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
6 |
7 | from twocaptcha import TwoCaptcha
8 |
9 | # in this example we store the API key inside environment variables that can be set like:
10 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12 | # you can just set the API key directly to it's value like:
13 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
14 |
15 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16 |
17 | solver = TwoCaptcha(api_key)
18 |
19 | try:
20 | result = solver.datadome(
21 | captcha_url="https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c...",
22 | pageurl="https://mysite.com/page/with/datadome",
23 | userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
24 | proxy={
25 | 'type': 'HTTP',
26 | 'uri': 'login:password@IP_address:PORT'
27 | }
28 | )
29 |
30 | except Exception as e:
31 | sys.exit(e)
32 |
33 | else:
34 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/examples/friendly_captcha.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.friendly_captcha(
20 | sitekey='FCMGEMUD2KTDSQ5H',
21 | url='https://friendlycaptcha.com/demo',
22 | )
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/examples/friendly_captcha_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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | config = {
17 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18 | 'apiKey': api_key,
19 | 'softId': 123,
20 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21 | 'defaultTimeout': 120,
22 | 'recaptchaTimeout': 600,
23 | 'pollingInterval': 10,
24 | }
25 |
26 | solver = TwoCaptcha(**config)
27 |
28 | try:
29 | result = solver.friendly_captcha(sitekey='FCMGEMUD2KTDSQ5H',
30 | url='https://friendlycaptcha.com/demo',
31 | # proxy={
32 | # 'type': 'HTTPS',
33 | # 'uri': 'login:password@IP_address:PORT'
34 | # }
35 | )
36 |
37 | except Exception as e:
38 | sys.exit(e)
39 |
40 | else:
41 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
6 |
7 | # in this example we store the API key inside environment variables that can be set like:
8 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10 | # you can just set the API key directly to it's value like:
11 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
12 |
13 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14 |
15 | solver = TwoCaptcha(api_key)
16 |
17 | try:
18 | result = solver.funcaptcha(sitekey='69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC',
19 | url='https://mysite.com/page/with/funcaptcha',
20 | surl='https://client-api.arkoselabs.com')
21 |
22 | except Exception as e:
23 | sys.exit(e)
24 |
25 | else:
26 | sys.exit('result: ' + str(result))
27 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
6 |
7 | # in this example we store the API key inside environment variables that can be set like:
8 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10 | # you can just set the API key directly to it's value like:
11 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
12 |
13 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14 |
15 | solver = TwoCaptcha(api_key, defaultTimeout=180, pollingInterval=15)
16 |
17 | try:
18 | result = solver.funcaptcha(
19 | sitekey='FB18D9DB-BAFF-DDAC-A33B-6CF22267BC0A',
20 | url='https://mysite.com/page/with/funcaptcha',
21 | surl='https://client-api.arkoselabs.com',
22 | userAgent=
23 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36',
24 | **{'data[key]': 'value'}, #optional data param used by some websites
25 | proxy={
26 | 'type': 'HTTP',
27 | 'uri': 'login:password@123.123.123.123:8080'
28 | })
29 |
30 | except Exception as e:
31 | sys.exit(e)
32 |
33 | else:
34 | sys.exit('result: ' + str(result))
35 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | """
19 | Important: the value of the 'challenge' parameter is dynamic, for each request to our API you need to get a new value.
20 | """
21 |
22 | resp = requests.get("https://2captcha.com/api/v1/captcha-demo/gee-test/init-params")
23 | challenge = resp.json()['challenge']
24 |
25 | try:
26 | result = solver.geetest(gt='81388ea1fc187e0c335c0a8907ff2625',
27 | apiServer='http://api.geetest.com',
28 | challenge=challenge,
29 | url='https://2captcha.com/demo/geetest')
30 |
31 | except Exception as e:
32 | sys.exit(e)
33 |
34 | else:
35 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key, defaultTimeout=300, pollingInterval=10, extendedResponse=True)
17 |
18 | """
19 | Important: the value of the 'challenge' parameter is dynamic, for each request to our API you need to get a new value.
20 | """
21 |
22 | resp = requests.get("https://2captcha.com/api/v1/captcha-demo/gee-test/init-params")
23 | challenge = resp.json()['challenge']
24 |
25 | try:
26 | result = solver.geetest(
27 | gt='81388ea1fc187e0c335c0a8907ff2625',
28 | apiServer='http://api.geetest.com',
29 | challenge=challenge,
30 | url='https://2captcha.com/demo/geetest',
31 | # proxy={
32 | # 'type': 'HTTPS',
33 | # 'uri': 'login:password@IP_address:PORT'
34 | # }
35 | )
36 |
37 | except Exception as e:
38 | sys.exit(e)
39 |
40 | else:
41 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
20 | url='https://2captcha.com/demo/geetest-v4')
21 |
22 | except Exception as e:
23 | sys.exit(e)
24 |
25 | else:
26 | sys.exit('result: ' + str(result))
27 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | config = {
17 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18 | 'apiKey': api_key,
19 | 'softId': 123,
20 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21 | 'defaultTimeout': 120,
22 | 'recaptchaTimeout': 600,
23 | 'pollingInterval': 10,
24 | }
25 |
26 | solver = TwoCaptcha(**config)
27 |
28 | try:
29 | result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
30 | url='https://2captcha.com/demo/geetest-v4',
31 | # proxy={
32 | # 'type': 'HTTPS',
33 | # 'uri': 'login:password@IP_address:PORT'
34 | # }
35 | )
36 |
37 | except Exception as e:
38 | sys.exit(e)
39 |
40 | else:
41 | sys.exit('result: ' + str(result))
42 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.grid('./images/grid_2.jpg',
20 | hintText='Select all images with an Orange',
21 | rows=3,
22 | cols=3)
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
29 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
8 |
9 | # in this example we store the API key inside environment variables that can be set like:
10 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12 | # you can just set the API key directly to it's value like:
13 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
14 |
15 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16 |
17 | solver = TwoCaptcha(api_key)
18 |
19 | with open('./images/grid_2.jpg', 'rb') as f:
20 | b64 = b64encode(f.read()).decode('utf-8')
21 |
22 | try:
23 | result = solver.grid(b64,
24 | hintText='Select all images with an Orange',
25 | rows=3,
26 | cols=3)
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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key, defaultTimeout=100, pollingInterval=12)
17 |
18 | try:
19 | result = solver.grid(
20 | file='./images/grid_2.jpg',
21 | rows=3,
22 | cols=3,
23 | previousId=0,
24 | canSkip=0,
25 | lang='en',
26 | hintImg='./images/grid_hint.jpg',
27 | # hintText='Select all images with an Orange',
28 | )
29 |
30 | except Exception as e:
31 | sys.exit(e)
32 |
33 | else:
34 | sys.exit('result: ' + str(result))
35 |
--------------------------------------------------------------------------------
/examples/images/canvas.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/canvas.jpg
--------------------------------------------------------------------------------
/examples/images/canvas_hint.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/canvas_hint.jpg
--------------------------------------------------------------------------------
/examples/images/grid.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/grid.jpg
--------------------------------------------------------------------------------
/examples/images/grid_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/grid_2.jpg
--------------------------------------------------------------------------------
/examples/images/grid_hint.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/grid_hint.jpg
--------------------------------------------------------------------------------
/examples/images/normal.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/normal.jpg
--------------------------------------------------------------------------------
/examples/images/normal_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/normal_2.jpg
--------------------------------------------------------------------------------
/examples/images/rotate.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2captcha/2captcha-python/20d3f59ebcac2e2f72187fc6dcbdaf6a35d42794/examples/images/rotate.jpg
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.keycaptcha(
20 | s_s_c_user_id=184015,
21 | s_s_c_session_id='e34ddd2c72e67593ac0b4ca8e4f44725',
22 | s_s_c_web_server_sign='a5ebd41ae22348b2cdbdc211792e982d',
23 | s_s_c_web_server_sign2='29255689423dd92990f8d06de50560d0',
24 | url='https://2captcha.com/demo/keycaptcha')
25 |
26 | except Exception as e:
27 | sys.exit(e)
28 |
29 | else:
30 | sys.exit('result: ' + str(result))
31 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | try:
30 | result = solver.keycaptcha(s_s_c_user_id=184015,
31 | s_s_c_session_id='e34ddd2c72e67593ac0b4ca8e4f44725',
32 | s_s_c_web_server_sign='a5ebd41ae22348b2cdbdc211792e982d',
33 | s_s_c_web_server_sign2='29255689423dd92990f8d06de50560d0',
34 | url='https://2captcha.com/demo/keycaptcha',
35 | # proxy = {'type': 'HTTPS',
36 | # 'uri': 'login:password@IP_address:PORT'}
37 | )
38 |
39 |
40 | except Exception as e:
41 | sys.exit(e)
42 |
43 | else:
44 | sys.exit('result: ' + str(result))
45 |
46 |
--------------------------------------------------------------------------------
/examples/lemin.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
4 |
5 | from twocaptcha import TwoCaptcha
6 |
7 | # in this example we store the API key inside environment variables that can be set like:
8 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
9 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
10 | # you can just set the API key directly to it's value like:
11 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
12 |
13 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
14 |
15 | solver = TwoCaptcha(api_key)
16 |
17 | try:
18 | result = solver.lemin(captcha_id='CROPPED_5a29582_ca114c2f3314482c84cd32fc7d2feb63',
19 | div_id='lemin-cropped-captcha',
20 | url='https://2captcha.com/demo/lemin')
21 |
22 |
23 | except Exception as e:
24 | sys.exit(e)
25 |
26 | else:
27 | sys.exit('result: ' + str(result))
28 |
--------------------------------------------------------------------------------
/examples/mtcaptcha.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.mtcaptcha(
20 | sitekey='MTPublic-KzqLY1cKH',
21 | url='https://2captcha.com/demo/mtcaptcha',
22 | )
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/examples/mtcaptcha_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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | config = {
17 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18 | 'apiKey': api_key,
19 | 'softId': 123,
20 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21 | 'defaultTimeout': 120,
22 | 'recaptchaTimeout': 600,
23 | 'pollingInterval': 10,
24 | }
25 |
26 | solver = TwoCaptcha(**config)
27 |
28 | try:
29 | result = solver.mtcaptcha(sitekey='MTPublic-KzqLY1cKH',
30 | url='https://2captcha.com/demo/mtcaptcha',
31 | # proxy={
32 | # 'type': 'HTTPS',
33 | # 'uri': 'login:password@IP_address:PORT'
34 | # }
35 | )
36 |
37 | except Exception as e:
38 | sys.exit(e)
39 |
40 | else:
41 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.normal('./images/normal.jpg')
20 |
21 | except Exception as e:
22 | sys.exit(e)
23 |
24 | else:
25 | sys.exit('result: ' + str(result))
26 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
8 |
9 | # in this example we store the API key inside environment variables that can be set like:
10 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12 | # you can just set the API key directly to it's value like:
13 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
14 |
15 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16 |
17 | solver = TwoCaptcha(api_key)
18 |
19 | with open('./images/normal.jpg', 'rb') as f:
20 | b64 = b64encode(f.read()).decode('utf-8')
21 |
22 | try:
23 | result = solver.normal(b64)
24 |
25 | except Exception as e:
26 | sys.exit(e)
27 |
28 | else:
29 | sys.exit('result: ' + str(result))
30 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key, defaultTimeout=30, pollingInterval=5)
17 |
18 | try:
19 | result = solver.normal(
20 | './images/normal_2.jpg',
21 | numeric=4,
22 | minLen=4,
23 | maxLen=20,
24 | phrase=0,
25 | caseSensitive=0,
26 | calc=0,
27 | lang='en',
28 | # hintImg='./images/normal_hint.jpg',
29 | # hintText='Type red symbols only',
30 | )
31 |
32 | except Exception as e:
33 | sys.exit(e)
34 |
35 | else:
36 | sys.exit('result: ' + str(result))
37 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.recaptcha(
20 | sitekey='6LdO5_IbAAAAAAeVBL9TClS19NUTt5wswEb3Q7C5',
21 | url='https://2captcha.com/demo/recaptcha-v2-invisible')
22 |
23 | except Exception as e:
24 | sys.exit(e)
25 |
26 | else:
27 | sys.exit('result: ' + str(result))
28 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | try:
30 | result = solver.recaptcha(
31 | sitekey='6LdO5_IbAAAAAAeVBL9TClS19NUTt5wswEb3Q7C5',
32 | url='https://2captcha.com/demo/recaptcha-v2-invisible',
33 | invisible=1,
34 | enterprise=0,
35 | # datas="bM-8CwwOmqyYCLWatmabvfyYR97ytF95tgu...",
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 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.recaptcha(
20 | sitekey='6LfdxboZAAAAAMtnONIt4DJ8J1t4wMC-kVG02zIO',
21 | url='https://2captcha.com/demo/recaptcha-v3',
22 | action='login',
23 | version='v3')
24 |
25 | except Exception as e:
26 | sys.exit(e)
27 |
28 | else:
29 | sys.exit('result: ' + str(result))
30 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | try:
30 | result = solver.recaptcha(
31 | sitekey='6LfdxboZAAAAAMtnONIt4DJ8J1t4wMC-kVG02zIO',
32 | url='https://2captcha.com/demo/recaptcha-v3',
33 | version='v3',
34 | enterprise=0,
35 | action='verify',
36 | score=0.7
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 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.rotate('./images/rotate.jpg')
20 |
21 | except Exception as e:
22 | sys.exit(e)
23 |
24 | else:
25 | sys.exit('result: ' + str(result))
26 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key, defaultTimeout=100, pollingInterval=10)
17 |
18 | try:
19 | result = solver.rotate(
20 | 'images/rotate.jpg',
21 | angle=40,
22 | lang='en',
23 | # hintImg = 'images/rotate_hint.jpg'
24 | hintText='Put the images in the correct way up')
25 |
26 | except Exception as e:
27 | sys.exit(e)
28 |
29 | else:
30 | sys.exit('result: ' + str(result))
31 |
--------------------------------------------------------------------------------
/examples/tencent.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.tencent(
20 | app_id="913522596",
21 | url="https://mysite.com/page/with/tencent"
22 | )
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/examples/tencent_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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | try:
30 | result = solver.tencent(app_id="197325555",
31 | url="https://your.site/result-receiver",
32 | # proxy={
33 | # 'type': 'HTTPS',
34 | # 'uri': 'ub6900fef552505bc-zone-custom-session-JcIHpmDKv-sessTime-1:ub6900fef552505bc@43.152.113.55:2333'
35 | # }
36 | )
37 |
38 | except Exception as e:
39 | sys.exit(e)
40 |
41 | else:
42 | sys.exit('result: ' + str(result))
43 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.text('If tomorrow is Saturday, what day is today?')
20 |
21 | except Exception as e:
22 | sys.exit(e)
23 |
24 | else:
25 | print(result)
26 | sys.exit('result: ' + str(result))
27 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key, defaultTimeout=40, pollingInterval=10)
17 |
18 | try:
19 | result = solver.text('If tomorrow is Saturday, what day is today?',
20 | lang='en')
21 |
22 | except Exception as e:
23 | sys.exit(e)
24 |
25 | else:
26 | sys.exit('result: ' + str(result))
27 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.turnstile(
20 | sitekey='0x4AAAAAAAVrOwQWPlm3Bnr5',
21 | url='https://2captcha.com/demo/cloudflare-turnstile',
22 | )
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
29 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | try:
30 | result = solver.turnstile(sitekey='0x4AAAAAAAVrOwQWPlm3Bnr5',
31 | url='https://2captcha.com/demo/cloudflare-turnstile',
32 | # data="str",
33 | # pagedata="str",
34 | # action="str",
35 | # 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"
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/yandex_smart.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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 | solver = TwoCaptcha(api_key)
17 |
18 | try:
19 | result = solver.yandex_smart(
20 | sitekey="FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR",
21 | url="https://www.site.com/page/"
22 | )
23 |
24 | except Exception as e:
25 | sys.exit(e)
26 |
27 | else:
28 | sys.exit('result: ' + str(result))
--------------------------------------------------------------------------------
/examples/yandex_smart_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 twocaptcha import TwoCaptcha
7 |
8 | # in this example we store the API key inside environment variables that can be set like:
9 | # export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10 | # set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11 | # you can just set the API key directly to it's value like:
12 | # api_key="1abc234de56fab7c89012d34e56fa7b8"
13 |
14 | api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15 |
16 |
17 | config = {
18 | 'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19 | 'apiKey': api_key,
20 | 'softId': 123,
21 | # 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22 | 'defaultTimeout': 120,
23 | 'recaptchaTimeout': 600,
24 | 'pollingInterval': 10,
25 | }
26 |
27 | solver = TwoCaptcha(**config)
28 |
29 | try:
30 | result = solver.yandex_smart(sitekey="FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR",
31 | url="https://www.site.com/page/",
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 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | requests>=2.20.0
--------------------------------------------------------------------------------
/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('twocaptcha/__init__.py', 'r') as f:
12 | return re.search(r'__version__ = ["\'](.*?)["\']', f.read()).group(1)
13 |
14 |
15 | setup(name='2captcha-python',
16 | version=get_version(),
17 | description='Python module for easy integration with 2Captcha API',
18 | long_description=long_description,
19 | long_description_content_type="text/markdown",
20 | url='https://github.com/2captcha/2captcha-python/',
21 | install_requires=['requests'],
22 | author='2Captcha',
23 | author_email='info@2captcha.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 | '2captcha', 'captcha', 'api', 'captcha solver', 'reCAPTCHA',
37 | 'FunCaptcha', 'Geetest', 'image captcha', 'Coordinates', 'Click Captcha',
38 | 'Geetest V4', 'Lemin captcha', 'Amazon WAF', 'Cloudflare Turnstile',
39 | 'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'cybersiara'],
40 | python_requires='>=3.6',
41 | test_suite='tests')
42 |
--------------------------------------------------------------------------------
/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 twocaptcha import TwoCaptcha
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 = TwoCaptcha('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': 4580})
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/canvas_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import unittest
4 |
5 | from abstract import AbstractTest
6 |
7 | file = '../examples/images/canvas.jpg'
8 | hint = 'Draw around apple'
9 |
10 | checks = {'canvas': 1, 'recaptcha': 1, 'textinstructions': hint}
11 |
12 |
13 | class CanvasTest(AbstractTest):
14 | def test_file_param(self):
15 |
16 | sends = {'method': 'post', 'file': file, **checks}
17 | return self.send_return(sends,
18 | self.solver.canvas,
19 | file=file,
20 | hintText=hint)
21 |
22 | def test_base64_param(self):
23 |
24 | b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
25 | sends = {
26 | 'method': 'base64',
27 | 'body': b64,
28 | **checks,
29 | }
30 |
31 | return self.send_return(sends,
32 | self.solver.canvas,
33 | file=b64,
34 | hintText=hint)
35 |
36 | def test_all_params(self):
37 |
38 | hint_img = '../examples/images/canvas_hint.jpg'
39 |
40 | params = {
41 | 'previousId': 0,
42 | 'canSkip': 0,
43 | 'lang': 'en',
44 | 'hintImg': hint_img,
45 | 'hintText': hint
46 | }
47 |
48 | sends = {
49 | 'method': 'post',
50 | 'previousID': 0,
51 | 'can_no_answer': 0,
52 | 'lang': 'en',
53 | 'files': {
54 | 'file': file,
55 | 'imginstructions': hint_img
56 | },
57 | **checks
58 | }
59 |
60 | return self.send_return(sends, self.solver.canvas, file=file, **params)
61 |
62 | def test_not_found(self):
63 |
64 | return self.invalid_file(self.solver.canvas, hintText=hint)
65 |
66 |
67 | if __name__ == '__main__':
68 |
69 | unittest.main()
70 |
--------------------------------------------------------------------------------
/tests/test_amazon_waf.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 AmazonWAFTest(AbstractTest):
11 |
12 |
13 | def test_all_params(self):
14 |
15 |
16 | params = {
17 | 'sitekey' : 'AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AFsClhVgr5q0UFRdXhhHEwiAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMLMbH8d6uQSrYTraoAgEQgDvtSNxdEyG7Zu393cHyPdWNCZgeIB52+W7fCTI8U5z15z1NdPUdnB1ZHoK7ewpwoSMm5mzkJJld0cnvGw==',
18 | 'url' : 'https://www.site.com/page/',
19 | 'iv' : 'CgAAYDJb9CAAACAq',
20 | 'context' : 'wCho9T9OcETTT8fu1k6+rszr5aGt4eLd+K3mHpV8VbSkjAWJGJx/iQ16RKDCTQBtU5OSeE+SQqoS5iTzhgGtvwgmBbr7X/I+aXaNfb2JRZ8eJ7CnQpM9QRwnv7vGgrGRBGhkh/jaVYmXdy0j0x21s3dCBlA4VN3naDHIweZqkyhXqJBNI1Ep8OMSnhXtPebboB117aBW4IU4XEOii8EE1G4Z7ndWhrNVVXYYwVoxfnSqfYX//CJir6dZfLMbCt5t7NnO8yjsx/YHGVXFVBt2Zrj0ZTxowoYbHU/BKyFaXgUj+ZQ='
21 | }
22 |
23 | sends = {
24 | 'method' : 'amazon_waf',
25 | 'sitekey' : 'AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AFsClhVgr5q0UFRdXhhHEwiAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMLMbH8d6uQSrYTraoAgEQgDvtSNxdEyG7Zu393cHyPdWNCZgeIB52+W7fCTI8U5z15z1NdPUdnB1ZHoK7ewpwoSMm5mzkJJld0cnvGw==',
26 | 'iv' : 'CgAAYDJb9CAAACAq',
27 | 'context' : 'wCho9T9OcETTT8fu1k6+rszr5aGt4eLd+K3mHpV8VbSkjAWJGJx/iQ16RKDCTQBtU5OSeE+SQqoS5iTzhgGtvwgmBbr7X/I+aXaNfb2JRZ8eJ7CnQpM9QRwnv7vGgrGRBGhkh/jaVYmXdy0j0x21s3dCBlA4VN3naDHIweZqkyhXqJBNI1Ep8OMSnhXtPebboB117aBW4IU4XEOii8EE1G4Z7ndWhrNVVXYYwVoxfnSqfYX//CJir6dZfLMbCt5t7NnO8yjsx/YHGVXFVBt2Zrj0ZTxowoYbHU/BKyFaXgUj+ZQ=',
28 | 'pageurl' : 'https://www.site.com/page/',
29 | }
30 |
31 | return self.send_return(sends, self.solver.amazon_waf, **params)
32 |
33 |
34 | if __name__ == '__main__':
35 |
36 | unittest.main()
37 |
38 |
39 | # sitekey='AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AFsClhVgr5q0UFRdXhhHEwiAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMLMbH8d6uQSrYTraoAgEQgDvtSNxdEyG7Zu393cHyPdWNCZgeIB52+W7fCTI8U5z15z1NdPUdnB1ZHoK7ewpwoSMm5mzkJJld0cnvGw==',
40 | # iv='CgAAYDJb9CAAACAq',
41 | # context='wCho9T9OcETTT8fu1k6+rszr5aGt4eLd+K3mHpV8VbSkjAWJGJx/iQ16RKDCTQBtU5OSeE+SQqoS5iTzhgGtvwgmBbr7X/I+aXaNfb2JRZ8eJ7CnQpM9QRwnv7vGgrGRBGhkh/jaVYmXdy0j0x21s3dCBlA4VN3naDHIweZqkyhXqJBNI1Ep8OMSnhXtPebboB117aBW4IU4XEOii8EE1G4Z7ndWhrNVVXYYwVoxfnSqfYX//CJir6dZfLMbCt5t7NnO8yjsx/YHGVXFVBt2Zrj0ZTxowoYbHU/BKyFaXgUj+ZQ=',
42 | # url='https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest',
--------------------------------------------------------------------------------
/tests/test_atb_captcha.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 | class AtbCaptchaTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | 'app_id': 'af25e409b33d722a95e56a230ff8771c',
16 | 'api_server': 'https://cap.aisecurius.com',
17 | 'url': 'http://mysite.com/'
18 | }
19 |
20 | sends = {
21 | 'method': 'atb_captcha',
22 | 'app_id': 'af25e409b33d722a95e56a230ff8771c',
23 | 'api_server': 'https://cap.aisecurius.com',
24 | 'pageurl': 'http://mysite.com/'
25 | }
26 |
27 | return self.send_return(sends, self.solver.atb_captcha, **params)
28 |
29 |
30 | if __name__ == '__main__':
31 | unittest.main()
--------------------------------------------------------------------------------
/tests/test_canvas.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import unittest
4 |
5 |
6 | file = '../examples/images/canvas.jpg'
7 | hint = 'Draw around apple'
8 | hint_img = '../examples/images/canvas_hint.jpg'
9 |
10 | checks = {'canvas' : 1, 'recaptcha' : 1, 'textinstructions' : hint}
11 |
12 |
13 | try:
14 | from .abstract import AbstractTest
15 |
16 | file = file[3:]
17 | hint_img = hint_img[3:]
18 |
19 | except ImportError:
20 | from abstract import AbstractTest
21 |
22 |
23 |
24 |
25 |
26 |
27 | class CanvasTest(AbstractTest):
28 |
29 | def test_file_param(self):
30 |
31 | sends = {'method': 'post', 'file': file, **checks}
32 | return self.send_return(sends, self.solver.canvas, file=file, hintText=hint)
33 |
34 |
35 |
36 | def test_base64_param(self):
37 |
38 | b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
39 | sends = {
40 | 'method': 'base64',
41 | 'body' : b64,
42 | **checks,
43 | }
44 |
45 | return self.send_return(sends, self.solver.canvas, file=b64, hintText=hint)
46 |
47 |
48 |
49 | def test_all_params(self):
50 |
51 |
52 | params = {
53 | 'previousId' : 0,
54 | 'canSkip' : 0,
55 | 'lang' : 'en',
56 | 'hintImg' : hint_img,
57 | 'hintText' : hint
58 | }
59 |
60 |
61 | sends = {
62 | 'method' : 'post',
63 | 'previousID' : 0,
64 | 'can_no_answer' : 0,
65 | 'lang' : 'en',
66 | 'files' : {'file': file,'imginstructions': hint_img},
67 | **checks
68 | }
69 |
70 | return self.send_return(sends, self.solver.canvas, file=file, **params)
71 |
72 |
73 |
74 | def test_not_found(self):
75 |
76 | return self.invalid_file(self.solver.canvas, hintText=hint)
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | if __name__ == '__main__':
87 |
88 | unittest.main()
89 |
90 |
--------------------------------------------------------------------------------
/tests/test_capy.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 CapyTest(AbstractTest):
13 |
14 |
15 | def test_all_params(self):
16 |
17 |
18 | params = {
19 | 'sitekey' : 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
20 | 'url' : 'http://mysite.com/',
21 | }
22 |
23 | sends = {
24 | 'method' : 'capy',
25 | 'captchakey' : 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
26 | 'pageurl' : 'http://mysite.com/',
27 | }
28 |
29 | return self.send_return(sends, self.solver.capy, **params)
30 |
31 |
32 |
33 |
34 |
35 | if __name__ == '__main__':
36 |
37 | unittest.main()
38 |
39 |
--------------------------------------------------------------------------------
/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/test_cutcaptcha.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 | class CutcaptchaTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | 'misery_key': 'ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
16 | 'apikey': 'SAs61IAI',
17 | 'url': 'https://www.site.com/page/',
18 | }
19 |
20 | sends = {
21 | 'method': 'cutcaptcha',
22 | 'api_key': 'SAs61IAI',
23 | 'misery_key': 'ad52c87af17e2ec09b8d918c9f00416b1cb8c320',
24 | 'pageurl': 'https://www.site.com/page/',
25 | }
26 |
27 | return self.send_return(sends, self.solver.cutcaptcha, **params)
28 |
29 |
30 | if __name__ == '__main__':
31 | unittest.main()
--------------------------------------------------------------------------------
/tests/test_cybersiara.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 | class CybersiaraTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | 'master_url_id': 'tpjOCKjjpdzv3d8Ub2E9COEWKt1vl1Mv',
16 | 'pageurl': 'https://demo.mycybersiara.com/',
17 | 'userAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36',
18 | }
19 |
20 | sends = {
21 | 'method': 'cybersiara',
22 | 'master_url_id': 'tpjOCKjjpdzv3d8Ub2E9COEWKt1vl1Mv',
23 | 'pageurl': 'https://demo.mycybersiara.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 | }
26 |
27 | return self.send_return(sends, self.solver.cybersiara, **params)
28 |
29 |
30 | if __name__ == '__main__':
31 | unittest.main()
32 |
33 |
--------------------------------------------------------------------------------
/tests/test_datadome.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 | class DatadomeTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | 'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c',
16 | 'pageurl': 'https://mysite.com/page/with/datadome',
17 | 'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
18 | 'proxy': {'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'}
19 | }
20 |
21 | sends = {
22 | 'method': 'datadome',
23 | 'captcha_url': 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAZirHgKBVrxwAsVuKlQ%3D%3D&c',
24 | 'pageurl': 'https://mysite.com/page/with/datadome',
25 | 'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
26 | 'proxy': 'login:password@IP_address:PORT',
27 | 'proxytype': 'HTTP'
28 | }
29 |
30 | return self.send_return(sends, self.solver.datadome, **params)
31 |
32 |
33 | if __name__ == '__main__':
34 | unittest.main()
--------------------------------------------------------------------------------
/tests/test_friendly_captcha.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 | class FriendlyCaptchaTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | 'sitekey': 'FCMGEMUD2KTDSQ5H',
16 | 'url': 'https://friendlycaptcha.com/demo',
17 | }
18 |
19 | sends = {
20 | 'method': 'friendly_captcha',
21 | 'sitekey': 'FCMGEMUD2KTDSQ5H',
22 | 'pageurl': 'https://friendlycaptcha.com/demo',
23 | }
24 |
25 | return self.send_return(sends, self.solver.friendly_captcha, **params)
26 |
27 |
28 | if __name__ == '__main__':
29 | unittest.main()
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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://2captcha.com/demo/geetest-v4', }
21 |
22 | sends = {
23 | 'method' : 'geetest_v4',
24 | 'captcha_id' : 'e392e1d7fd421dc63325744d5a2b9c73',
25 | 'pageurl' : 'https://2captcha.com/demo/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tests/test_hcaptcha.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 HcaptchaTest(AbstractTest):
13 |
14 |
15 | def test_all_params(self):
16 |
17 |
18 | params = {
19 | 'sitekey' : 'f1ab2cdefa3456789012345b6c78d90e',
20 | 'url' : 'https://www.site.com/page/',
21 | }
22 |
23 | sends = {
24 | 'method' : 'hcaptcha',
25 | 'sitekey' : 'f1ab2cdefa3456789012345b6c78d90e',
26 | 'pageurl' : 'https://www.site.com/page/',
27 | }
28 |
29 | return self.send_return(sends, self.solver.hcaptcha, **params)
30 |
31 |
32 |
33 |
34 |
35 | if __name__ == '__main__':
36 |
37 | unittest.main()
38 |
39 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tests/test_lemin.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 LeminTest(AbstractTest):
13 |
14 |
15 | def test_all_params(self):
16 |
17 |
18 | params = {
19 | 'captcha_id' : 'CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',
20 | 'div_id' : 'lemin-cropped-captcha',
21 | 'api_server' : 'https://api.leminnow.com/',
22 | 'url' : 'http://mysite.com/',
23 | }
24 |
25 | sends = {
26 | 'method' : 'lemin',
27 | 'captcha_id' : 'CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',
28 | 'div_id' : 'lemin-cropped-captcha',
29 | 'api_server' : 'https://api.leminnow.com/',
30 | 'pageurl' : 'http://mysite.com/',
31 | }
32 |
33 | return self.send_return(sends, self.solver.lemin, **params)
34 |
35 |
36 |
37 |
38 |
39 | if __name__ == '__main__':
40 |
41 | unittest.main()
42 |
43 |
--------------------------------------------------------------------------------
/tests/test_mtcaptcha.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 | class MTCaptchaTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | 'sitekey': 'MTPublic-KzqLY1cKH',
16 | 'url': 'https://2captcha.com/demo/mtcaptcha',
17 | }
18 |
19 | sends = {
20 | 'method': 'mt_captcha',
21 | 'sitekey': 'MTPublic-KzqLY1cKH',
22 | 'pageurl': 'https://2captcha.com/demo/mtcaptcha',
23 | }
24 |
25 | return self.send_return(sends, self.solver.mtcaptcha, **params)
26 |
27 |
28 | if __name__ == '__main__':
29 | unittest.main()
30 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | 'datas' : 'Crb7VsRAQaBqoaQQtHQQ'
23 | }
24 |
25 | sends = {
26 | 'method' : 'userrecaptcha',
27 | 'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
28 | 'pageurl' : 'https://mysite.com/page/with/recaptcha',
29 | 'invisible': 1,
30 | 'enterprise': 0,
31 | 'action' : 'verify',
32 | 'version' : 'v2',
33 | 'data-s' : 'Crb7VsRAQaBqoaQQtHQQ'
34 | }
35 |
36 | return self.send_return(sends, self.solver.recaptcha, **params)
37 |
38 |
39 | def test_v3(self):
40 |
41 | params = {
42 | 'sitekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
43 | 'url' : 'https://mysite.com/page/with/recaptcha',
44 | 'invisible' : 1,
45 | 'action' : 'verify',
46 | 'version' : 'v3',
47 | }
48 |
49 | sends = {
50 | 'method' : 'userrecaptcha',
51 | 'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
52 | 'pageurl' : 'https://mysite.com/page/with/recaptcha',
53 | 'invisible' : 1,
54 | 'enterprise': 0,
55 | 'action' : 'verify',
56 | 'version' : 'v3',
57 | }
58 |
59 | return self.send_return(sends, self.solver.recaptcha, **params)
60 |
61 |
62 |
63 | if __name__ == '__main__':
64 |
65 | unittest.main()
66 |
67 |
--------------------------------------------------------------------------------
/tests/test_rotate.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import unittest
4 |
5 |
6 | files = ['../examples/images/rotate.jpg']
7 |
8 | hint_img = '../examples/images/grid_hint.jpg'
9 | hint_text = 'Put the images in the correct way up'
10 |
11 |
12 | try:
13 | from .abstract import AbstractTest
14 |
15 | files = [f[3:] for f in files]
16 | hint_img = hint_img[3:]
17 |
18 | except ImportError:
19 | from abstract import AbstractTest
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | files_dict = {f'file_{e+1}': f for e, f in enumerate(files)}
28 |
29 | checks = {'method' : 'rotatecaptcha'}
30 |
31 |
32 |
33 | class RotateTest(AbstractTest):
34 |
35 | def test_single_file(self):
36 |
37 | sends = {'method': 'post', 'file': files[0], **checks}
38 | return self.send_return(sends, self.solver.rotate, files=files[0])
39 |
40 |
41 |
42 | def test_file_param(self):
43 |
44 | sends = {'method': 'post',
45 | 'files': {'file_1': files[0]},
46 | **checks}
47 |
48 | return self.send_return(sends, self.solver.rotate, files=files[:1])
49 |
50 |
51 |
52 | def test_files_list(self):
53 |
54 | sends = {'method': 'post', 'files': files_dict, **checks}
55 | return self.send_return(sends, self.solver.rotate, files=files)
56 |
57 |
58 |
59 | def test_files_dict(self):
60 |
61 | sends = {'method': 'post', 'files': files_dict, **checks}
62 | return self.send_return(sends, self.solver.rotate, files=files_dict)
63 |
64 |
65 |
66 | def test_all_params(self):
67 |
68 | params = {
69 | 'angle' : 40,
70 | 'lang' : 'en',
71 | 'hintImg' : hint_img,
72 | 'hintText' : hint_text
73 | }
74 |
75 |
76 | sends = {
77 | 'method' : 'rotatecaptcha',
78 | 'angle' : 40,
79 | 'lang' : 'en',
80 | 'textinstructions' : hint_text,
81 | 'files' : {'file': files[0],'imginstructions': hint_img},
82 | **checks
83 | }
84 |
85 | return self.send_return(sends, self.solver.rotate, file=files[0], **params)
86 |
87 |
88 |
89 | def test_not_found(self):
90 |
91 | return self.invalid_file(self.solver.rotate)
92 |
93 |
94 |
95 | def test_too_many(self):
96 |
97 | return self.too_many_files(self.solver.rotate)
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | if __name__ == '__main__':
107 |
108 | unittest.main()
109 |
110 |
--------------------------------------------------------------------------------
/tests/test_tencent.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 | class TencentTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | "app_id": "197322596",
16 | "url": "https://www.holla.world/random-video-chat#app"
17 | }
18 |
19 | sends = {
20 | "method": "tencent",
21 | "app_id": "197322596",
22 | "pageurl": "https://www.holla.world/random-video-chat#app",
23 | }
24 |
25 | return self.send_return(sends, self.solver.tencent, **params)
26 |
27 |
28 | if __name__ == '__main__':
29 | unittest.main()
30 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tests/test_yandex_smart_captcha.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 | class YandexSmartCaptchaTest(AbstractTest):
12 |
13 | def test_all_params(self):
14 | params = {
15 | 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdPpL4O',
16 | 'url': 'https://www.site.com/page/',
17 | }
18 |
19 | sends = {
20 | 'method': 'yandex',
21 | 'sitekey': 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdPpL4O',
22 | 'pageurl': 'https://www.site.com/page/',
23 | }
24 |
25 | return self.send_return(sends, self.solver.yandex_smart, **params)
26 |
27 |
28 | if __name__ == '__main__':
29 | unittest.main()
--------------------------------------------------------------------------------
/twocaptcha/__init__.py:
--------------------------------------------------------------------------------
1 | from .api import ApiClient
2 | from .solver import (TwoCaptcha, SolverExceptions, ValidationException,
3 | NetworkException, ApiException, TimeoutException)
4 |
5 | """
6 | Python 3 package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha,
7 | funcaptcha, geetest and solve any other captchas.
8 |
9 | website 2captcha [https://2captcha.com/]
10 | support@2captcha.com
11 | # License: MIT
12 | """
13 |
14 | __author__ = '2captcha'
15 | __version__ = '1.5.1'
16 |
--------------------------------------------------------------------------------
/twocaptcha/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 = '2captcha.com'):
16 | self.post_url = post_url
17 |
18 |
19 | def in_(self, files={}, **kwargs):
20 | '''
21 |
22 | sends POST-request (files and/or params) to solve captcha
23 |
24 | Parameters
25 | ----------
26 | files : TYPE, optional
27 | DESCRIPTION. The default is {}.
28 | **kwargs : TYPE
29 | DESCRIPTION.
30 |
31 | Raises
32 | ------
33 | NetworkException
34 | DESCRIPTION.
35 | ApiException
36 | DESCRIPTION.
37 |
38 | Returns
39 | -------
40 | resp : TYPE
41 | DESCRIPTION.
42 |
43 | '''
44 |
45 | try:
46 | current_url = 'https://'+self.post_url+'/in.php'
47 | if files:
48 |
49 | files = {key: open(path, 'rb') for key, path in files.items()}
50 | resp = requests.post(current_url,
51 | data=kwargs,
52 | files=files)
53 |
54 | [f.close() for f in files.values()]
55 |
56 | elif 'file' in kwargs:
57 |
58 | with open(kwargs.pop('file'), 'rb') as f:
59 | resp = requests.post(current_url,
60 | data=kwargs,
61 | files={'file': f})
62 |
63 | else:
64 | resp = requests.post(current_url,
65 | data=kwargs)
66 |
67 | except requests.RequestException as e:
68 | raise NetworkException(e)
69 |
70 | if resp.status_code != 200:
71 | raise NetworkException(f'bad response: {resp.status_code}')
72 |
73 | resp = resp.content.decode('utf-8')
74 |
75 | if 'ERROR' in resp:
76 | raise ApiException(resp)
77 |
78 | return resp
79 |
80 | def res(self, **kwargs):
81 | '''
82 | sends additional GET-requests (solved captcha, balance, report etc.)
83 |
84 | Parameters
85 | ----------
86 | **kwargs : TYPE
87 | DESCRIPTION.
88 |
89 | Raises
90 | ------
91 | NetworkException
92 | DESCRIPTION.
93 | ApiException
94 | DESCRIPTION.
95 |
96 | Returns
97 | -------
98 | resp : TYPE
99 | DESCRIPTION.
100 |
101 | '''
102 |
103 | try:
104 | current_url_out = 'https://'+self.post_url+'/res.php'
105 | resp = requests.get(current_url_out, params=kwargs)
106 |
107 | if resp.status_code != 200:
108 | raise NetworkException(f'bad response: {resp.status_code}')
109 |
110 | resp = resp.content.decode('utf-8')
111 |
112 | if 'ERROR' in resp:
113 | raise ApiException(resp)
114 |
115 | except requests.RequestException as e:
116 | raise NetworkException(e)
117 |
118 | return resp
119 |
--------------------------------------------------------------------------------
/twocaptcha/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 TwoCaptcha():
37 | def __init__(self,
38 | apiKey,
39 | softId=4580,
40 | callback=None,
41 | defaultTimeout=120,
42 | recaptchaTimeout=600,
43 | pollingInterval=10,
44 | server = '2captcha.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 normal(self, file, **kwargs):
59 | '''Wrapper for solving a normal captcha (image).
60 |
61 | Parameters
62 | __________
63 | file : file
64 | Captcha image file. * required if you submit image as a file (method=post).
65 | body : str
66 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
67 | phrase : int, optional
68 | 0 - captcha contains one word. 1 - captcha contains two or more words.
69 | Default: 0.
70 | numeric : int, optional
71 | 0 - not specified. 1 - captcha contains only numbers. 2 - captcha contains only letters. 3 - captcha
72 | contains only numbers OR only letters. 4 - captcha MUST contain both numbers AND letters.
73 | Default: 0
74 | minLen : int, optional
75 | 0 - not specified. 1..20 - minimal number of symbols in captcha.
76 | Default: 0.
77 | maxLen : int, optional
78 | 0 - not specified. 1..20 - maximal number of symbols in captcha.
79 | Default: 0.
80 | caseSensitive : int, optional
81 | 0 - captcha in not case sensitive. 1 - captcha is case sensitive.
82 | Default: 0.
83 | calc : int, optional
84 | 0 - not specified. 1 - captcha requires calculation (e.g. type the result 4 + 8 = ).
85 | Default: 0.
86 | lang : str, optional
87 | Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
88 | hintText : str, optional
89 | Max 140 characters. Endcoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
90 | For example: type red symbols only.
91 | hintImg : img, optional
92 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
93 | instruction as text with textinstructions.
94 | softId : int, optional
95 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
96 | spendings of their software users.
97 | callback : str, optional
98 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
99 | the server. More info here https://2captcha.com/2captcha-api#pingback.
100 | '''
101 |
102 | method = self.get_method(file)
103 | result = self.solve(**method, **kwargs)
104 | return result
105 |
106 | def audio(self, file, lang, **kwargs):
107 | '''Wrapper for solving audio captcha.
108 |
109 | Parameters
110 | __________
111 | body : str
112 | Base64 encoded audio file in mp3 format. Max file size: 1 MB.
113 | lang : str
114 | The language of audio record. Supported languages are: "en", "ru", "de", "el", "pt", "fr".
115 | '''
116 |
117 | method = "audio"
118 |
119 | if not file:
120 | raise ValidationException('File is none')
121 | elif not '.' in file and len(file) > 50:
122 | body = file
123 | elif file.endswith(".mp3") and file.startswith("http"):
124 | response = requests.get(file)
125 | if response.status_code != 200:
126 | raise ValidationException(f'File could not be downloaded from url: {file}')
127 | body = b64encode(response.content).decode('utf-8')
128 | elif file.endswith(".mp3"):
129 | with open(file, "rb") as media:
130 | body = b64encode(media.read()).decode('utf-8')
131 | else:
132 | raise ValidationException('File extension is not .mp3 or it is not a base64 string.')
133 |
134 | if not lang or lang not in ("en", "ru", "de", "el", "pt", "fr"):
135 | raise ValidationException(f'Lang not in "en", "ru", "de", "el", "pt", "fr". You send {lang}')
136 |
137 | result = self.solve(body=body, method=method, **kwargs)
138 | return result
139 |
140 | def text(self, text, **kwargs):
141 | '''Wrapper for solving text captcha.
142 |
143 | Parameters
144 | __________
145 | text : str
146 | Max 140 characters. Endcoding: UTF-8. Text will be shown to worker to help him to solve the captcha correctly.
147 | For example: type red symbols only.
148 | lang: str, optional
149 | Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
150 | softId : int, optional
151 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
152 | spendings of their software users.
153 | callback : str, optional
154 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
155 | the server. More info here https://2captcha.com/2captcha-api#pingback.
156 | '''
157 |
158 | result = self.solve(text=text, method='post', **kwargs)
159 | return result
160 |
161 | def recaptcha(self, sitekey, url, version='v2', enterprise=0, **kwargs):
162 | '''Wrapper for solving recaptcha (v2, v3).
163 |
164 | Parameters
165 | _______________
166 | sitekey : str
167 | Value of sitekey parameter you found on page.
168 | url : str
169 | Full URL of the page where you see the reCAPTCHA.
170 | domain : str, optional
171 | Domain used to load the captcha: google.com or recaptcha.net. Default: google.com.
172 | invisible : int, optional
173 | 1 - means that reCAPTCHA is invisible. 0 - normal reCAPTCHA. Default: 0.
174 | version : str, optional
175 | v3 — defines that you're sending a reCAPTCHA V3. Default: v2.
176 | enterprise : str, optional
177 | 1 - defines that you're sending reCAPTCHA Enterpise. Default: 0.
178 | action : str, optional
179 | Value of action parameter you found on page. Default: verify.
180 | score : str, only for v3, optional
181 | The score needed for resolution. Currently, it's almost impossible to get token with score higher than 0.3.
182 | Default: 0.4.
183 | data-s : str, only for v2, optional
184 | Value of data-s parameter you found on page. Curenttly applicable for Google Search and other Google services.
185 | cookies : str, only for v2, optional
186 | Your cookies that will be passed to our worker who solve the captha. We also return worker's cookies in the
187 | response if you use json=1. Format: KEY:Value, separator: semicolon, example: KEY1:Value1;KEY2:Value2;
188 | userAgent : str, only for v2, optional
189 | Your userAgent that will be passed to our worker and used to solve the captcha.
190 | softId : int, optional
191 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
192 | spendings of their software users.
193 | callback : str, optional
194 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
195 | the server. More info here https://2captcha.com/2captcha-api#pingback.
196 | proxy : dict, optional
197 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
198 | '''
199 |
200 | params = {
201 | 'googlekey': sitekey,
202 | 'url': url,
203 | 'method': 'userrecaptcha',
204 | 'version': version,
205 | 'enterprise': enterprise,
206 | **kwargs,
207 | }
208 |
209 | result = self.solve(timeout=self.recaptcha_timeout, **params)
210 | return result
211 |
212 | def funcaptcha(self, sitekey, url, **kwargs):
213 | '''Wrapper for solving funcaptcha.
214 |
215 | Parameters
216 | __________
217 | sitekey : str
218 | Value of pk or data-pkey parameter you found on page.
219 | url : str
220 | Full URL of the page where you see the FunCaptcha.
221 | surl : str, optional
222 | Value of surl parameter you found on page.
223 | userAgent: str, optional
224 | Tells us to use your user-agent value.
225 | data[key] : str, optional
226 | Custom data to pass to FunCaptcha. For example: data[blob]=stringValue.
227 | softId : str, optional
228 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
229 | spendings of their software users.
230 | callback : str, optional
231 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
232 | the server. More info here https://2captcha.com/2captcha-api#pingback.
233 | proxy : dict, optional
234 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
235 | '''
236 |
237 | result = self.solve(publickey=sitekey,
238 | url=url,
239 | method='funcaptcha',
240 | **kwargs)
241 | return result
242 |
243 | def geetest(self, gt, challenge, url, **kwargs):
244 | '''Wrapper for solving geetest captcha.
245 |
246 | Parameters:
247 | __________
248 | gt : str
249 | Value of gt parameter you found on target website.
250 | challenge : str
251 | Value of challenge parameter you found on target website.
252 | url : str
253 | Full URL of the page where you see Geetest captcha.
254 | offline : num, optional
255 | In rare cases initGeetest can be called with offline parameter. If the call uses offline: true, set the
256 | value to 1. Default: 0.
257 | new_captcha : num, optional
258 | In rare cases initGeetest can be called with new_captcha parameter. If the call uses new_captcha: true, set
259 | the value to 1. Mostly used with offline parameter.
260 | userAgent : str, optional
261 | Your userAgent that will be passed to our worker and used to solve the captcha.
262 | apiServer : str, optional
263 | Value of api_server parameter you found on target website.
264 | softId : int, optional
265 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
266 | spendings of their software users.
267 | callback : str, optional
268 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
269 | the server. More info here https://2captcha.com/2captcha-api#pingback.
270 | proxy : dict, optional
271 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
272 | '''
273 |
274 | result = self.solve(gt=gt,
275 | challenge=challenge,
276 | url=url,
277 | method='geetest',
278 | **kwargs)
279 | return result
280 |
281 | def hcaptcha(self, sitekey, url, **kwargs):
282 | '''Wrapper for solving hcaptcha.
283 |
284 | Parameters
285 | __________
286 | sitekey : str
287 | Value of data-sitekey parameter you found on page.
288 | url : str
289 | Full URL of the page where you bypass the captcha.
290 | invisible : num, optional
291 | Use 1 for invisible version of hcaptcha. Currently it is a very rare case.
292 | Default: 0.
293 | data : str, optional
294 | Custom data that is used in some implementations of hCaptcha, mostly with invisible=1. In most cases you see
295 | it as rqdata inside network requests. Format: "data": "rqDataValue".
296 | domain : str, optional
297 | Domain used to load the captcha: hcaptcha.com or js.hcaptcha.com. Default: hcaptcha.com.
298 | softId : int, optional
299 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
300 | spendings of their software users.
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://2captcha.com/2captcha-api#pingback.
304 | proxy : dict, optional
305 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
306 | '''
307 |
308 | result = self.solve(sitekey=sitekey,
309 | url=url,
310 | method='hcaptcha',
311 | **kwargs)
312 | return result
313 |
314 | def keycaptcha(self, s_s_c_user_id, s_s_c_session_id,
315 | s_s_c_web_server_sign, s_s_c_web_server_sign2, url,
316 | **kwargs):
317 | '''Wrapper for solving.
318 |
319 | Parameters
320 | __________
321 | s_s_c_user_id : str
322 | Value of s_s_c_user_id parameter you found on page.
323 | s_s_c_session_id : str
324 | Value of s_s_c_session_id parameter you found on page.
325 | s_s_c_web_server_sign : str
326 | Value of s_s_c_web_server_sign parameter you found on page.
327 | s_s_c_web_server_sign2 : str
328 | Value of s_s_c_web_server_sign2 parameter you found on page.
329 | url : str
330 | Full URL of the page where you see the KeyCaptcha.
331 | softId : int, optional
332 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
333 | spendings of their software users.
334 | callback : str, optional
335 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
336 | the server. More info here https://2captcha.com/2captcha-api#pingback.
337 | proxy : dict, optional
338 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
339 | '''
340 |
341 | params = {
342 | 's_s_c_user_id': s_s_c_user_id,
343 | 's_s_c_session_id': s_s_c_session_id,
344 | 's_s_c_web_server_sign': s_s_c_web_server_sign,
345 | 's_s_c_web_server_sign2': s_s_c_web_server_sign2,
346 | 'url': url,
347 | 'method': 'keycaptcha',
348 | **kwargs,
349 | }
350 |
351 | result = self.solve(**params)
352 | return result
353 |
354 | def capy(self, sitekey, url, **kwargs):
355 | '''Wrapper for solving capy.
356 |
357 | Parameters
358 | __________
359 | sitekey : str
360 | The domain part of script URL you found on page. Default value: https://jp.api.capy.me/.
361 | url : str
362 | Full URL of the page where you see the captcha.
363 | api_server : str, optional
364 | The domain part of script URL you found on page. Default value: https://jp.api.capy.me/.
365 | version : str, optional
366 | The version of captcha task: "puzzle" (assemble a puzzle) or "avatar" (drag an object). Default: puzzle.
367 | softId : int, optional
368 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
369 | spendings of their software users.
370 | callback : str, optional
371 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
372 | the server. More info here https://2captcha.com/2captcha-api#pingback.
373 | proxy : dict, optional
374 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
375 | '''
376 |
377 | result = self.solve(captchakey=sitekey,
378 | url=url,
379 | method='capy',
380 | **kwargs)
381 | return result
382 |
383 | def grid(self, file, **kwargs):
384 | '''Wrapper for solving grid captcha (image).
385 |
386 | Required:
387 | file : file
388 | Captcha image file. * required if you submit image as a file (method=post).
389 | body : str
390 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
391 | hintText : str
392 | Max 140 characters. Endcoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select images
393 | with trees. Not required if you're sending instruction as an image with imginstructions.
394 | hintImg : img
395 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
396 | instruction as text with textinstructions.
397 | rows : int, optional
398 | Number of rows in reCAPTCHA grid.
399 | cols : itn, optional
400 | Number of columns in reCAPTCHA grid.
401 | previousId : str, optional
402 | Id of your previous request with the same captcha challenge.
403 | canSkip : int, optional
404 | 0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's
405 | possible that there's no images matching to the instruction. We'll provide a button "No matching images" to
406 | worker, and you will receive No_matching_images as answer.
407 | Default: 0.
408 | lang: str, optional
409 | Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
410 | softId : int, optional
411 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
412 | spendings of their software users.
413 | callback : str, optional
414 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
415 | the server. More info here https://2captcha.com/2captcha-api#pingback.
416 | proxy : dict, optional
417 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
418 | '''
419 |
420 | method = self.get_method(file)
421 |
422 | params = {
423 | 'recaptcha': 1,
424 | **method,
425 | **kwargs,
426 | }
427 |
428 | result = self.solve(**params)
429 | return result
430 |
431 | def canvas(self, file, **kwargs):
432 | '''Wrapper for solving canvas captcha (image).
433 |
434 | Parameters
435 | __________
436 | file : file
437 | Captcha image file. * required if you submit image as a file (method=post).
438 | body : str
439 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
440 | hintText : str
441 | Max 140 characters. Endcoding: UTF-8. Text with instruction for solving reCAPTCHA. For example: select
442 | images with trees. Not required if you're sending instruction as an image with imginstructions.
443 | hintImg : img
444 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
445 | instruction as text with textinstructions.
446 | canSkip : int, optional
447 | 0 - not specified. 1 - possibly there's no images that fit the instruction. Set the value to 1 only if it's
448 | possible that there's no images matching to the instruction. We'll provide a button "No matching images" to
449 | worker, and you will receive No_matching_images as answer.
450 | Default: 0.
451 | lang : int, optional
452 | 0 - not specified. 1 - Cyrillic captcha. 2 - Latin captcha.
453 | Default: 0.
454 | softId : int, optional
455 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
456 | spendings of their software users.
457 | callback : str, optional
458 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
459 | the server. More info here https://2captcha.com/2captcha-api#pingback.
460 | '''
461 |
462 | if not ('hintText' in kwargs or 'hintImg' in kwargs):
463 | raise ValidationException(
464 | 'parameters required: hintText and/or hintImg')
465 |
466 | method = self.get_method(file)
467 |
468 | params = {
469 | 'recaptcha': 1,
470 | 'canvas': 1,
471 | **method,
472 | **kwargs,
473 | }
474 |
475 | result = self.solve(**params)
476 | return result
477 |
478 | def coordinates(self, file, **kwargs):
479 | '''Wrapper for solving coordinates captcha (image).
480 |
481 | Parameters
482 | __________
483 | file : file
484 | Captcha image file. * required if you submit image as a file (method=post).
485 | body : str
486 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
487 | hintText : str
488 | Max 140 characters. Endcoding: UTF-8. Text with instruction for solving the captcha. For example: click on
489 | images with ghosts. Not required if the image already contains the instruction.
490 | hintImg : img
491 | Max 400x150px, 100 kB. Image with instruction for solving reCAPTCHA. Not required if you're sending
492 | instruction as text with textinstructions.
493 | lang : str, optional
494 | Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
495 | min_clicks : int, optional
496 | The minimum number of clicks that need to be done.
497 | max_clicks : int, optional
498 | The maximum number of clicks that can be done.
499 | softId : int, optional
500 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
501 | spendings of their software users.
502 | callback : str, optional
503 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
504 | the server. More info here https://2captcha.com/2captcha-api#pingback.
505 | '''
506 |
507 | method = self.get_method(file)
508 |
509 | params = {
510 | 'coordinatescaptcha': 1,
511 | **method,
512 | **kwargs,
513 | }
514 |
515 | result = self.solve(**params)
516 | return result
517 |
518 | def rotate(self, files, **kwargs):
519 | '''Wrapper for solving rotate captcha (image).
520 |
521 | Parameters
522 | __________
523 | files : file
524 | Captcha image file. * required if you submit image as a file (method=post).
525 | body : str
526 | Base64-encoded captcha image. * required if you submit image as Base64-encoded string (method=base64).
527 | angle : int, optional
528 | Angle for one rotation step in degrees. If not defined we'll use the default value for FunCaptcha: 40 degrees.
529 | Default: 40.
530 | lang : str, optional
531 | Language code. See the list of supported languages https://2captcha.com/2captcha-api#language.
532 | hintImg : str, optional
533 | Image with instruction for worker to help him to solve captcha correctly.
534 | hintText : str, optional
535 | Text will be shown to worker to help him to to solve captcha correctly.
536 | softId : int, optional
537 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
538 | spendings of their software users.
539 | callback : str, optional
540 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
541 | the server. More info here https://2captcha.com/2captcha-api#pingback.
542 | proxy : dict, optional
543 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
544 | '''
545 |
546 | if isinstance(files, str):
547 |
548 | file = self.get_method(files)['file']
549 |
550 | result = self.solve(file=file, method='rotatecaptcha', **kwargs)
551 | return result
552 |
553 | elif isinstance(files, dict):
554 | files = list(files.values())
555 |
556 | files = self.extract_files(files)
557 |
558 | result = self.solve(files=files, method='rotatecaptcha', **kwargs)
559 | return result
560 |
561 |
562 | def geetest_v4(self, captcha_id, url, **kwargs):
563 | '''Wrapper for solving geetest_v4 captcha.
564 |
565 | Parameters
566 | __________
567 | captcha_id : str
568 | Value of captcha_id parameter you found on target website.
569 | url: str
570 | Full URL of the page where you see Geetest captcha.
571 | softId : int, optional
572 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
573 | spendings of their software users.
574 | callback : str, optional
575 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
576 | the server. More info here https://2captcha.com/2captcha-api#pingback.
577 | proxy : dict, optional
578 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
579 | '''
580 |
581 | result = self.solve(captcha_id=captcha_id,
582 | url=url,
583 | method='geetest_v4',
584 | **kwargs)
585 | return result
586 |
587 |
588 | def lemin(self, captcha_id, div_id, url, **kwargs):
589 | '''Wrapper for solving Lemin Cropped Captcha.
590 |
591 | Parameters
592 | __________
593 | captcha_id : str
594 | Value of captcha_id parameter you found on page.
595 | div_id : str
596 | The id of captcha parent div element.
597 | url : str
598 | Full URL of the page where you see the captcha.
599 | api_server : str, optional
600 | The domain part of script URL you found on page. Default value: https://api.leminnow.com/.
601 | softId : int, optional
602 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
603 | spendings of their software users.
604 | callback : str, optional
605 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
606 | the server. More info here https://2captcha.com/2captcha-api#pingback.
607 | proxy : dict, optional
608 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
609 | '''
610 |
611 | result = self.solve(captcha_id=captcha_id,
612 | div_id=div_id,
613 | url=url,
614 | method='lemin',
615 | **kwargs)
616 | return result
617 |
618 | def atb_captcha(self, app_id, api_server, url, **kwargs):
619 | '''Wrapper for solving atbCAPTCHA.
620 |
621 | Parameters
622 | __________
623 | app_id : str
624 | The value of appId parameter in the website source code.
625 | api_server : str
626 | The value of apiServer parameter in the website source code.
627 | url : str
628 | The full URL of target web page where the captcha is loaded. We do not open the page, not a problem if it is
629 | available only for authenticated users.
630 | proxy : dict, optional
631 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
632 |
633 | '''
634 |
635 | result = self.solve(app_id=app_id,
636 | api_server=api_server,
637 | url=url,
638 | method='atb_captcha',
639 | **kwargs)
640 | return result
641 |
642 |
643 | def turnstile(self, sitekey, url, **kwargs):
644 | '''Wrapper for solving Cloudflare Turnstile.
645 |
646 | Parameters
647 | __________
648 | sitekey : str
649 | Value of sitekey parameter you found on page.
650 | url : str
651 | Full URL of the page where you see the captcha.
652 | useragent : str
653 | User-Agent of your browser. Must match the User-Agent you use to access the site.
654 | Use only modern browsers released within the last 6 months.
655 | action : str. optional
656 | Value of optional action parameter you found on page, can be defined in data-action attribute or passed
657 | to turnstile.render call.
658 | data : str, optional
659 | The value of cData passed to turnstile.render call. Also can be defined in data-cdata attribute.
660 | pagedata : str, optional
661 | The value of the chlPageData parameter when calling turnstile.render.
662 | softId : int, optional
663 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
664 | spendings of their software users.
665 | callback : str, optional
666 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
667 | the server. More info here https://2captcha.com/2captcha-api#pingback.
668 | proxy : dict, optional
669 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
670 | '''
671 |
672 | result = self.solve(sitekey=sitekey,
673 | url=url,
674 | method='turnstile',
675 | **kwargs)
676 | return result
677 |
678 |
679 | def amazon_waf(self, sitekey, iv, context, url, **kwargs):
680 | '''Wrapper for solving Amazon WAF.
681 |
682 | Parameters
683 | __________
684 | sitekey : str
685 | Value of key parameter you found on the page.
686 | iv : str
687 | Value of iv parameter you found on the page.
688 | context : str
689 | Value of optional context parameter you found on page.
690 | url : str
691 | Full URL of the page where you see the captcha.
692 | challenge_script : str, optional
693 | The source URL of challenge.js script on the page.
694 | captcha_script : str, optional
695 | The source URL of captcha.js script on the page.
696 | softId : int, optional
697 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
698 | spendings of their software users.
699 | callback : str, optional
700 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
701 | the server. More info here https://2captcha.com/2captcha-api#pingback.
702 | proxy : dict, optional
703 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
704 | '''
705 |
706 | result = self.solve(sitekey=sitekey,
707 | iv=iv,
708 | context=context,
709 | url=url,
710 | method='amazon_waf',
711 | **kwargs)
712 |
713 | return result
714 |
715 | def mtcaptcha(self, sitekey, url, **kwargs):
716 | '''Wrapper for solving MTCaptcha.
717 |
718 | Parameters
719 | __________
720 | sitekey : str
721 | The value of sitekey parameter found on the page.
722 | url : str
723 | Full URL of the page where you solve the captcha.
724 | softId : int, optional
725 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
726 | spendings of their software users.
727 | callback : str, optional
728 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
729 | the server. More info here https://2captcha.com/2captcha-api#pingback.
730 | proxy : dict, optional
731 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
732 | '''
733 |
734 | result = self.solve(sitekey=sitekey,
735 | url=url,
736 | method='mt_captcha',
737 | **kwargs)
738 | return result
739 |
740 | def friendly_captcha(self, sitekey, url, **kwargs):
741 | '''Wrapper for solving Friendly Captcha.
742 |
743 | Parameters
744 | __________
745 | sitekey : str
746 | The value of data-sitekey attribute of captcha's div element on page.
747 | url : str
748 | Full URL of the page where you solve the captcha.
749 | softId : int, optional
750 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
751 | spendings of their software users.
752 | callback : str, optional
753 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
754 | the server. More info here https://2captcha.com/2captcha-api#pingback.
755 | proxy : dict, optional
756 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
757 | '''
758 |
759 | result = self.solve(sitekey=sitekey,
760 | url=url,
761 | method='friendly_captcha',
762 | **kwargs)
763 | return result
764 |
765 | def tencent(self, app_id, url, **kwargs):
766 | '''Wrapper for solving Tencent captcha.
767 |
768 | Parameters
769 | __________
770 | app_id : str
771 | The value of appId parameter in the website source code.
772 | url : str
773 | The full URL of target web page where the captcha is loaded. We do not open the page, not a problem if it is
774 | available only for authenticated users.
775 | softId : int, optional
776 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
777 | spendings of their software users.
778 | callback : str, optional
779 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
780 | the server. More info here https://2captcha.com/2captcha-api#pingback.
781 | proxy : dict, optional
782 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
783 | '''
784 |
785 | result = self.solve(app_id=app_id,
786 | url=url,
787 | method="tencent",
788 | **kwargs)
789 | return result
790 |
791 | def cutcaptcha(self, misery_key, apikey, url, **kwargs):
792 | '''Wrapper for solving Friendly Captcha.
793 |
794 | Parameters
795 | __________
796 | misery_key : str
797 | The value of CUTCAPTCHA_MISERY_KEY variable defined on page.
798 | apikey : str
799 | The value of data-apikey attribute of iframe's body. Also, the name of javascript file included on the page.
800 | url : str
801 | Full URL of the page where you solve the captcha.
802 | softId : int, optional
803 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
804 | spendings of their software users.
805 | callback : str, optional
806 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
807 | the server. More info here https://2captcha.com/2captcha-api#pingback.
808 | proxy : dict, optional
809 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
810 | '''
811 |
812 | result = self.solve(misery_key=misery_key,
813 | api_key=apikey,
814 | url=url,
815 | method='cutcaptcha',
816 | **kwargs)
817 | return result
818 |
819 | def datadome(self, captcha_url, pageurl, userAgent, proxy, **kwargs):
820 | """Wrapper for solving DataDome Captcha.
821 |
822 | Parameters
823 | __________
824 | captcha_url: str
825 | The value of the 'src' parameter for the 'iframe' element containing the captcha on the page.
826 | pageurl: str
827 | Full URL of the page that triggers the captcha when you go to it.
828 | userAgent: str
829 | User-Agent of the browser that will be used by the employee when loading the captcha.
830 | proxy : dict
831 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
832 | """
833 |
834 | result = self.solve(method='datadome',
835 | captcha_url=captcha_url,
836 | pageurl=pageurl,
837 | userAgent=userAgent,
838 | proxy=proxy,
839 | **kwargs)
840 | return result
841 |
842 | def cybersiara(self, master_url_id, pageurl, userAgent, **kwargs):
843 | '''Wrapper for solving CyberSiARA captcha.
844 |
845 | Parameters
846 | __________
847 | master_url_id : str
848 | The value of the MasterUrlId parameter from the request to API/CyberSiara/GetCyberSiara.
849 | pageurl : str
850 | Full URL of the page with captcha.
851 | userAgent : str
852 | User-Agent of your browser.
853 | proxy : dict, optional
854 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
855 | '''
856 | result = self.solve(method='cybersiara',
857 | master_url_id=master_url_id,
858 | pageurl=pageurl,
859 | userAgent=userAgent,
860 | **kwargs)
861 | return result
862 |
863 | def yandex_smart(self, sitekey, url, **kwargs):
864 | '''Wrapper for solving Yandex Smart.
865 |
866 | Parameters
867 | __________
868 | sitekey : str
869 | The value of data-sitekey attribute of captcha's div element on page.
870 | url : str
871 | Full URL of the page where you solve the captcha.
872 | softId : int, optional
873 | ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
874 | spendings of their software users.
875 | callback : str, optional
876 | URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
877 | the server. More info here https://2captcha.com/2captcha-api#pingback.
878 | proxy : dict, optional
879 | {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
880 | userAgent: str, optional
881 | User-Agent of the browser that will be used by the employee when loading the captcha.
882 | '''
883 |
884 | result = self.solve(sitekey=sitekey,
885 | url=url,
886 | method='yandex',
887 | **kwargs)
888 | return result
889 |
890 | def solve(self, timeout=0, polling_interval=0, **kwargs):
891 | '''Sends captcha, receives result.
892 |
893 | Parameters
894 | __________
895 | timeout : float
896 |
897 | polling_interval : int
898 |
899 | **kwargs : dict
900 | all captcha params
901 |
902 | Returns
903 |
904 | result : string
905 | '''
906 |
907 | id_ = self.send(**kwargs)
908 | result = {'captchaId': id_}
909 |
910 | if self.callback is None:
911 | timeout = float(timeout or self.default_timeout)
912 | sleep = int(polling_interval or self.polling_interval)
913 |
914 | code = self.wait_result(id_, timeout, sleep)
915 |
916 | if self.extendedResponse == True:
917 |
918 | new_code = {
919 | key if key != 'request' else 'code': value
920 | for key, value in code.items()
921 | if key != 'status'
922 | }
923 | result.update(new_code)
924 | else:
925 | result.update({'code': code})
926 |
927 | return result
928 |
929 | def wait_result(self, id_, timeout, polling_interval):
930 |
931 | max_wait = time.time() + timeout
932 |
933 | while time.time() < max_wait:
934 |
935 | try:
936 | return self.get_result(id_)
937 |
938 | except NetworkException:
939 |
940 | time.sleep(polling_interval)
941 |
942 | raise TimeoutException(f'timeout {timeout} exceeded')
943 |
944 | def get_method(self, file):
945 |
946 | if not file:
947 | raise ValidationException('File required')
948 |
949 | if not '.' in file and len(file) > 50:
950 | return {'method': 'base64', 'body': file}
951 |
952 | if file.startswith('http'):
953 | img_resp = requests.get(file)
954 | if img_resp.status_code != 200:
955 | raise ValidationException(f'File could not be downloaded from url: {file}')
956 | return {'method': 'base64', 'body': b64encode(img_resp.content).decode('utf-8')}
957 |
958 | if not os.path.exists(file):
959 | raise ValidationException(f'File not found: {file}')
960 |
961 | return {'method': 'post', 'file': file}
962 |
963 | def send(self, **kwargs):
964 | """This method can be used for manual captcha submission
965 |
966 | Parameters
967 | _________
968 | method : str
969 | The name of the method must be found in the documentation https://2captcha.com/2captcha-api
970 | kwargs: dict
971 | All captcha params
972 | Returns
973 |
974 | """
975 |
976 | params = self.default_params(kwargs)
977 | params = self.rename_params(params)
978 |
979 | params, files = self.check_hint_img(params)
980 |
981 | response = self.api_client.in_(files=files, **params)
982 |
983 | if not response.startswith('OK|'):
984 | raise ApiException(f'cannot recognize response {response}')
985 |
986 | return response[3:]
987 |
988 | def get_result(self, id_):
989 | import json
990 | """This method can be used for manual captcha answer polling.
991 |
992 | Parameters
993 | __________
994 | id_ : str
995 | ID of the captcha sent for solution
996 | Returns
997 |
998 | answer : text
999 | """
1000 |
1001 | if self.extendedResponse == True:
1002 |
1003 | response = self.api_client.res(key=self.API_KEY, action='get', id=id_, json=1)
1004 |
1005 | response_data = json.loads(response)
1006 |
1007 | if response_data.get("status") == 0:
1008 | raise NetworkException
1009 |
1010 | if not response_data.get("status") == 1:
1011 | raise ApiException(f'Unexpected status in response: {response_data}')
1012 |
1013 | return response_data
1014 |
1015 | else:
1016 |
1017 | response = self.api_client.res(key=self.API_KEY, action='get', id=id_)
1018 |
1019 | if response == 'CAPCHA_NOT_READY':
1020 | raise NetworkException
1021 |
1022 | if not response.startswith('OK|'):
1023 | raise ApiException(f'cannot recognize response {response}')
1024 |
1025 | return response[3:]
1026 |
1027 | def balance(self):
1028 | '''Get my balance
1029 |
1030 | Returns
1031 |
1032 | balance : float
1033 | '''
1034 |
1035 | response = self.api_client.res(key=self.API_KEY, action='getbalance')
1036 | return float(response)
1037 |
1038 | def report(self, id_, correct):
1039 | '''Report of solved captcha: good/bad.
1040 |
1041 | Parameters
1042 | __________
1043 | id_ : str
1044 | captcha ID
1045 |
1046 | correct : bool
1047 | True/False
1048 |
1049 | Returns
1050 | None.
1051 |
1052 | '''
1053 |
1054 | rep = 'reportgood' if correct else 'reportbad'
1055 | self.api_client.res(key=self.API_KEY, action=rep, id=id_)
1056 |
1057 | return
1058 |
1059 | def rename_params(self, params):
1060 |
1061 | replace = {
1062 | 'caseSensitive': 'regsense',
1063 | 'minLen': 'min_len',
1064 | 'maxLen': 'max_len',
1065 | 'minLength': 'min_len',
1066 | 'maxLength': 'max_len',
1067 | 'hintText': 'textinstructions',
1068 | 'hintImg': 'imginstructions',
1069 | 'url': 'pageurl',
1070 | 'score': 'min_score',
1071 | 'text': 'textcaptcha',
1072 | 'rows': 'recaptcharows',
1073 | 'cols': 'recaptchacols',
1074 | 'previousId': 'previousID',
1075 | 'canSkip': 'can_no_answer',
1076 | 'apiServer': 'api_server',
1077 | 'softId': 'soft_id',
1078 | 'callback': 'pingback',
1079 | 'datas': 'data-s',
1080 | }
1081 |
1082 | new_params = {
1083 | v: params.pop(k)
1084 | for k, v in replace.items() if k in params
1085 | }
1086 |
1087 | proxy = params.pop('proxy', '')
1088 | proxy and new_params.update({
1089 | 'proxy': proxy['uri'],
1090 | 'proxytype': proxy['type']
1091 | })
1092 |
1093 | new_params.update(params)
1094 |
1095 | return new_params
1096 |
1097 | def default_params(self, params):
1098 |
1099 | params.update({'key': self.API_KEY})
1100 |
1101 | callback = params.pop('callback', self.callback)
1102 | soft_id = params.pop('softId', self.soft_id)
1103 |
1104 | if callback: params.update({'callback': callback})
1105 | if soft_id: params.update({'softId': soft_id})
1106 |
1107 | self.has_callback = bool(callback)
1108 |
1109 | return params
1110 |
1111 | def extract_files(self, files):
1112 |
1113 | if len(files) > self.max_files:
1114 | raise ValidationException(
1115 | f'Too many files (max: {self.max_files})')
1116 |
1117 | not_exists = [f for f in files if not (os.path.exists(f))]
1118 |
1119 | if not_exists:
1120 | raise ValidationException(f'File not found: {not_exists}')
1121 |
1122 | files = {f'file_{e+1}': f for e, f in enumerate(files)}
1123 | return files
1124 |
1125 | def check_hint_img(self, params):
1126 |
1127 | hint = params.pop('imginstructions', None)
1128 | files = params.pop('files', {})
1129 |
1130 | if not hint:
1131 | return params, files
1132 |
1133 | if not '.' in hint and len(hint) > 50:
1134 | params.update({'imginstructions': hint})
1135 | return params, files
1136 |
1137 | if not os.path.exists(hint):
1138 | raise ValidationException(f'File not found: {hint}')
1139 |
1140 | if not files:
1141 | files = {'file': params.pop('file', {})}
1142 |
1143 | files.update({'imginstructions': hint})
1144 |
1145 | return params, files
1146 |
1147 |
1148 | if __name__ == '__main__':
1149 |
1150 | key = sys.argv[1]
1151 | sol = TwoCaptcha(key)
1152 |
--------------------------------------------------------------------------------