Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Examples of API requests for different captcha types are available on the [Pytho
- [Alibaba](#alibaba)
- [TSPD](#tspd)
- [Basilisk](#basilisk)
- [Drag & Drop](#drag--drop)
- [Other methods](#other-methods)
- [send / get\_result](#send--get_result)
- [balance](#balance)
Expand Down Expand Up @@ -611,6 +612,26 @@ result = solver.basilisk(pageurl='https://example.com/login',
)
```

### Drag & Drop

<sup>[API method description.](https://2captcha.com/2captcha-api#drag-and-drop-captcha)</sup>

Use this method to solve a captcha where one or more images need to be dragged onto specific positions on a background image.
`body` and each item in `images` can be a file path, a URL, or a Base64-encoded string.

Returns the standard result dictionary `{'captchaId': 'TASK_ID', 'code': 'COORDINATES'}`. The coordinates string in
`result['code']` contains one entry per image from `images`, in the same order, separated by `|`. An image that
wasn't moved may be returned by the API as `null`.

```python
result = solver.drag_and_drop(
body='path/to/background.jpg',
images=['path/to/image1.jpg', 'path/to/image2.jpg'],
)

coordinates = result['code']
```

## Other methods

### send / get_result
Expand Down
30 changes: 30 additions & 0 deletions examples/async/async_drag_and_drop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import asyncio
import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from twocaptcha import AsyncTwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = AsyncTwoCaptcha(api_key)


async def solve_captcha():
try:
return await solver.drag_and_drop(body='../images/drag_drop_main.jpeg',
images=['../images/drag_drop_image1.jpeg', '../images/drag_drop_image2.jpeg'])
except Exception as e:
sys.exit(e)


if __name__ == '__main__':
result = asyncio.run(solve_captcha())
sys.exit('result: ' + str(result))
42 changes: 42 additions & 0 deletions examples/async/async_drag_and_drop_base64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import asyncio
import os
import sys
from base64 import b64encode

import aiofiles

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from twocaptcha import AsyncTwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = AsyncTwoCaptcha(api_key)


async def solve_captcha():
async with aiofiles.open('../images/drag_drop_main.jpeg', 'rb') as f:
body_b64 = b64encode(await f.read()).decode('utf-8')

async with aiofiles.open('../images/drag_drop_image1.jpeg', 'rb') as f:
image1_b64 = b64encode(await f.read()).decode('utf-8')

async with aiofiles.open('../images/drag_drop_image2.jpeg', 'rb') as f:
image2_b64 = b64encode(await f.read()).decode('utf-8')

try:
return await solver.drag_and_drop(body=body_b64,
images=[image1_b64, image2_b64])
except Exception as e:
sys.exit(e)


if __name__ == '__main__':
result = asyncio.run(solve_captcha())
sys.exit('result: ' + str(result))
36 changes: 36 additions & 0 deletions examples/async/async_drag_and_drop_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import asyncio
import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from twocaptcha import AsyncTwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = AsyncTwoCaptcha(api_key, defaultTimeout=120, pollingInterval=10)


async def solve_captcha():
try:
return await solver.drag_and_drop(
body='../images/drag_drop_main.jpeg',
images=['../images/drag_drop_image1.jpeg', '../images/drag_drop_image2.jpeg'],
hintText='Drag the images to proper position',
language=0,
lang='en',
header_acao=0,
)
except Exception as e:
sys.exit(e)


if __name__ == '__main__':
result = asyncio.run(solve_captcha())
sys.exit('result: ' + str(result))
Binary file added examples/images/drag_drop_image1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/drag_drop_image2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/drag_drop_main.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions examples/sync/drag_and_drop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from twocaptcha import TwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key)

try:
result = solver.drag_and_drop(body='../images/drag_drop_main.jpeg',
images=['../images/drag_drop_image1.jpeg', '../images/drag_drop_image2.jpeg'])

except Exception as e:
sys.exit(str(e))

else:
sys.exit('result: ' + str(result))
36 changes: 36 additions & 0 deletions examples/sync/drag_and_drop_base64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
import os
from base64 import b64encode

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from twocaptcha import TwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key)

with open('../images/drag_drop_main.jpeg', 'rb') as f:
body_b64 = b64encode(f.read()).decode('utf-8')

with open('../images/drag_drop_image1.jpeg', 'rb') as f:
image1_b64 = b64encode(f.read()).decode('utf-8')

with open('../images/drag_drop_image2.jpeg', 'rb') as f:
image2_b64 = b64encode(f.read()).decode('utf-8')

try:
result = solver.drag_and_drop(body=body_b64,
images=[image1_b64, image2_b64])

except Exception as e:
sys.exit(str(e))

else:
sys.exit('result: ' + str(result))
32 changes: 32 additions & 0 deletions examples/sync/drag_and_drop_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

from twocaptcha import TwoCaptcha

# in this example we store the API key inside environment variables that can be set like:
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
# you can just set the API key directly to it's value like:
# api_key="1abc234de56fab7c89012d34e56fa7b8"

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key, defaultTimeout=120, pollingInterval=10)

try:
result = solver.drag_and_drop(
body='../images/drag_drop_main.jpeg',
images=['../images/drag_drop_image1.jpeg', '../images/drag_drop_image2.jpeg'],
hintText='Drag the images to proper position',
language=0,
lang='en',
header_acao=0,
)

except Exception as e:
sys.exit(str(e))

else:
sys.exit('result: ' + str(result))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def get_version():
'2captcha', 'captcha', 'api', 'captcha solver', 'reCAPTCHA',
'FunCaptcha', 'Geetest', 'image captcha', 'Coordinates', 'Click Captcha',
'Geetest V4', 'Lemin captcha', 'Amazon WAF', 'Cloudflare Turnstile',
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'VK Captcha', 'CaptchaFox', 'Prosopo', 'cybersiara', 'Hunt', 'Alibaba', 'TSPD', 'Basilisk'],
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'VK Captcha', 'CaptchaFox', 'Prosopo', 'cybersiara', 'Hunt', 'Alibaba', 'TSPD', 'Basilisk', 'Drag & Drop'],
python_requires='>=3.8',
test_suite='tests')
Loading