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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Examples of API requests for different captcha types are available on the [Pytho
- [Yidun](#yidun)
- [Hunt](#hunt)
- [Alibaba](#alibaba)
- [TSPD](#tspd)
- [Other methods](#other-methods)
- [send / get\_result](#send--get_result)
- [balance](#balance)
Expand Down Expand Up @@ -585,6 +586,19 @@ result = solver.alibaba(pageurl='https://www.example.com',
)
```

### TSPD

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

Use this method to solve TSPD captcha. Returns a JSON string with cookies.
```python
result = solver.tspd(pageurl='https://example.com/login',
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
)
```

## Other methods

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

sys.path.append(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.tspd(
pageurl='https://example.com/login',
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
)

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_tspd_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import asyncio
import sys
import os

sys.path.append(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')

config = {
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
'apiKey': api_key,
'softId': 123,
'defaultTimeout': 120,
'recaptchaTimeout': 600,
'pollingInterval': 10,
}

solver = AsyncTwoCaptcha(**config)

async def solve_captcha():
try:
return await solver.tspd(
pageurl='https://example.com/login',
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
)
except Exception as e:
sys.exit(e)

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

sys.path.append(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.tspd(
pageurl='https://example.com/login',
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
)

except Exception as e:
sys.exit(e)

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

sys.path.append(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')

config = {
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
'apiKey': api_key,
'softId': 123,
'defaultTimeout': 120,
'recaptchaTimeout': 600,
'pollingInterval': 10,
}

solver = TwoCaptcha(**config)

try:
result = solver.tspd(
pageurl='https://example.com/login',
tspd_cookie='TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
html_page_base64='PCFET0NUWVBFIGh0bWw+...',
proxy={'type': 'HTTP', 'uri': 'login:password@IP_address:PORT'},
useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
)

except Exception as e:
sys.exit(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'],
'Capy Puzzle', 'MTCaptcha', 'Friendly Captcha', 'Tencent', 'Cutcaptcha', 'DataDome', 'VK Captcha', 'CaptchaFox', 'Prosopo', 'cybersiara', 'Hunt', 'Alibaba', 'TSPD'],
python_requires='>=3.8',
test_suite='tests')
36 changes: 36 additions & 0 deletions tests/async/test_async_tspd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import unittest

try:
from .abstract_async import AsyncAbstractTest
except ImportError:
from abstract_async import AsyncAbstractTest


class AsyncTspd(AsyncAbstractTest):
def test_all_params(self):
params = {
'pageurl': 'https://example.com/login',
'tspd_cookie': 'TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
'html_page_base64': 'PCFET0NUWVBFIGh0bWw+...',
'proxy': {'type': 'HTTP',
'uri': 'login:password@IP_address:PORT'},
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
}

sends = {
'method': 'tspd',
'pageurl': 'https://example.com/login',
'tspd_cookie': 'TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
'html_page_base64': 'PCFET0NUWVBFIGh0bWw+...',
'proxytype': 'HTTP',
'proxy': 'login:password@IP_address:PORT',
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
}

self.send_return(sends, self.solver.tspd, **params)


if __name__ == '__main__':
unittest.main()
37 changes: 37 additions & 0 deletions tests/sync/test_tspd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

import unittest

try:
from .abstract import AbstractTest
except ImportError:
from abstract import AbstractTest


class CaptchaTspd(AbstractTest):

def test_all_params(self):
params = {
'pageurl': 'https://example.com/login',
'tspd_cookie': 'TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
'html_page_base64': 'PCFET0NUWVBFIGh0bWw+...',
'proxy': {'type': 'HTTP',
'uri': 'login:password@IP_address:PORT'},
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
}

sends = {
'method': 'tspd',
'pageurl': 'https://example.com/login',
'tspd_cookie': 'TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c',
'html_page_base64': 'PCFET0NUWVBFIGh0bWw+...',
'proxytype': 'HTTP',
'proxy': 'login:password@IP_address:PORT',
'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
}

return self.send_return(sends, self.solver.tspd, **params)


if __name__ == '__main__':
unittest.main()
26 changes: 26 additions & 0 deletions twocaptcha/async_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,32 @@ async def alibaba(self, pageurl, scene_id, prefix, **kwargs):

return await result

async def tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs):
'''Wrapper for solving TSPD captcha.

Parameters
__________
pageurl : str
Full URL of the page with the captcha.
tspd_cookie : str
Cookies received on the TSPD challenge page.
html_page_base64 : str
Full HTML of the challenge page, Base64 encoded.
proxy : dict
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
useragent : str, optional
Browser User-Agent. We recommend sending a valid Windows browser string.
'''
result = self.solve(
method="tspd",
pageurl=pageurl,
tspd_cookie=tspd_cookie,
html_page_base64=html_page_base64,
proxy=proxy,
**kwargs)

return await result

async def solve(self, timeout=0, polling_interval=0, **kwargs):
'''Sends captcha, receives result.

Expand Down
28 changes: 28 additions & 0 deletions twocaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class TwoCaptcha():
Wrapper for solving Hunt captcha.
alibaba(self, pageurl, scene_id, prefix, **kwargs)
Wrapper for solving Alibaba captcha.
tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs)
Wrapper for solving TSPD captcha.
solve(timeout=0, polling_interval=0, **kwargs)
Sends CAPTCHA data and retrieves the result.
balance()
Expand Down Expand Up @@ -1285,6 +1287,32 @@ def alibaba(self, pageurl, scene_id, prefix, **kwargs):

return result

def tspd(self, pageurl, tspd_cookie, html_page_base64, proxy, **kwargs):
'''Wrapper for solving TSPD captcha.

Parameters
__________
pageurl : str
Full URL of the page with the captcha.
tspd_cookie : str
Cookies received on the TSPD challenge page.
html_page_base64 : str
Full HTML of the challenge page, Base64 encoded.
proxy : dict
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
useragent : str, optional
Browser User-Agent. We recommend sending a valid Windows browser string.
'''
result = self.solve(
method="tspd",
pageurl=pageurl,
tspd_cookie=tspd_cookie,
html_page_base64=html_page_base64,
proxy=proxy,
**kwargs)

return result


def solve(self, timeout=0, polling_interval=0, **kwargs):
'''Sends captcha, receives result.
Expand Down