captchasonline 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: captchasonline
3
+ Version: 0.0.0
4
+ License-File: LICENSE
5
+ Dynamic: license-file
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ from .api import ApiClient
2
+ from .solver import CaptchasOnline
3
+
4
+ from .async_api import AsyncApiClient
5
+ from .async_solver import AsyncTwoCaptcha
6
+
7
+ from .solver import SolverExceptions, ValidationException, NetworkException, ApiException, TimeoutException
8
+
9
+
10
+ """
11
+ Python 3 package for easy integration with the API of Captchas.Online captcha solving service to bypass recaptcha,
12
+ funcaptcha, geetest and solve any other captchas.
13
+
14
+ website captchas.online [https://captchas.online/]
15
+ support@captchas.online
16
+ # License: MIT
17
+ """
18
+
19
+ __author__ = 'captchas.online'
20
+ __version__ = '2.1.2'
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import requests
4
+
5
+ try:
6
+ from .exceptions.api import NetworkException, ApiException
7
+ except ImportError:
8
+ from captchasonline.exceptions.api import NetworkException, ApiException
9
+
10
+
11
+ class ApiClient():
12
+ def __init__(self, post_url='captchas.online'):
13
+ self.post_url = post_url
14
+
15
+ def in_(self, files={}, **kwargs):
16
+ '''
17
+
18
+ sends POST-request (files and/or params) to solve captcha
19
+
20
+ Parameters
21
+ ----------
22
+ files : TYPE, optional
23
+ DESCRIPTION. The default is {}.
24
+ **kwargs : TYPE
25
+ DESCRIPTION.
26
+
27
+ Raises
28
+ ------
29
+ NetworkException
30
+ DESCRIPTION.
31
+ ApiException
32
+ DESCRIPTION.
33
+
34
+ Returns
35
+ -------
36
+ resp : TYPE
37
+ DESCRIPTION.
38
+
39
+ '''
40
+
41
+ try:
42
+ current_url = 'https://' + self.post_url + '/in.php'
43
+ if files:
44
+
45
+ files = {key: open(path, 'rb') for key, path in files.items()}
46
+ resp = requests.post(current_url,
47
+ data=kwargs,
48
+ files=files)
49
+
50
+ [f.close() for f in files.values()]
51
+
52
+ elif 'file' in kwargs:
53
+
54
+ with open(kwargs.pop('file'), 'rb') as f:
55
+ resp = requests.post(current_url,
56
+ data=kwargs,
57
+ files={'file': f})
58
+
59
+ else:
60
+ resp = requests.post(current_url,
61
+ data=kwargs)
62
+
63
+ except requests.RequestException as e:
64
+ raise NetworkException(e)
65
+
66
+ if resp.status_code != 200:
67
+ raise NetworkException(f'bad response: {resp.status_code}')
68
+
69
+ resp = resp.content.decode('utf-8')
70
+
71
+ if 'ERROR' in resp:
72
+ raise ApiException(resp)
73
+
74
+ return resp
75
+
76
+ def res(self, **kwargs):
77
+ '''
78
+ sends additional GET-requests (solved captcha, balance, report etc.)
79
+
80
+ Parameters
81
+ ----------
82
+ **kwargs : TYPE
83
+ DESCRIPTION.
84
+
85
+ Raises
86
+ ------
87
+ NetworkException
88
+ DESCRIPTION.
89
+ ApiException
90
+ DESCRIPTION.
91
+
92
+ Returns
93
+ -------
94
+ resp : TYPE
95
+ DESCRIPTION.
96
+
97
+ '''
98
+
99
+ try:
100
+ current_url_out = 'https://' + self.post_url + '/res.php'
101
+ resp = requests.get(current_url_out, params=kwargs)
102
+
103
+ if resp.status_code != 200:
104
+ raise NetworkException(f'bad response: {resp.status_code}')
105
+
106
+ resp = resp.content.decode('utf-8')
107
+
108
+ if 'ERROR' in resp:
109
+ raise ApiException(resp)
110
+
111
+ except requests.RequestException as e:
112
+ raise NetworkException(e)
113
+
114
+ return resp
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from contextlib import AsyncExitStack
4
+
5
+ import aiofiles
6
+ import httpx
7
+
8
+ try:
9
+ from .exceptions.api import NetworkException, ApiException
10
+ except ImportError:
11
+ from captchasonline.exceptions.api import NetworkException, ApiException
12
+
13
+
14
+ class AsyncApiClient():
15
+ def __init__(self, post_url='captchas.online'):
16
+ self.post_url = post_url
17
+
18
+ async def in_(self, files={}, **kwargs):
19
+ '''
20
+
21
+ sends POST-request (files and/or params) to solve captcha
22
+
23
+ Parameters
24
+ ----------
25
+ files : TYPE, optional
26
+ DESCRIPTION. The default is {}.
27
+ **kwargs : TYPE
28
+ DESCRIPTION.
29
+
30
+ Raises
31
+ ------
32
+ NetworkException
33
+ DESCRIPTION.
34
+ ApiException
35
+ DESCRIPTION.
36
+
37
+ Returns
38
+ -------
39
+ resp : TYPE
40
+ DESCRIPTION.
41
+
42
+ '''
43
+
44
+ try:
45
+ current_url = 'https://' + self.post_url + '/in.php'
46
+
47
+ async with httpx.AsyncClient(follow_redirects=True) as client:
48
+ if files:
49
+ async with AsyncExitStack() as stack:
50
+ file_objects = {}
51
+ for key, path in files.items():
52
+ file_handle = await stack.enter_async_context(aiofiles.open(path, 'rb'))
53
+ content = await file_handle.read()
54
+ file_objects[key] = content
55
+
56
+ resp = await client.post(current_url,
57
+ data=kwargs,
58
+ files=file_objects)
59
+
60
+ elif 'file' in kwargs:
61
+ file_path = kwargs.pop('file')
62
+ async with aiofiles.open(file_path, 'rb') as file_handle:
63
+ content = await file_handle.read()
64
+ resp = await client.post(current_url,
65
+ data=kwargs,
66
+ files={'file': content})
67
+ else:
68
+ resp = await client.post(current_url,
69
+ data=kwargs)
70
+
71
+ except httpx.RequestError as e:
72
+ raise NetworkException(e)
73
+
74
+ if resp.status_code != 200:
75
+ raise NetworkException(f'bad response: {resp.status_code}')
76
+
77
+ resp = resp.content.decode('utf-8')
78
+
79
+ if 'ERROR' in resp:
80
+ raise ApiException(resp)
81
+
82
+ return resp
83
+
84
+ async def res(self, **kwargs):
85
+ '''
86
+ sends additional GET-requests (solved captcha, balance, report etc.)
87
+
88
+ Parameters
89
+ ----------
90
+ **kwargs : TYPE
91
+ DESCRIPTION.
92
+
93
+ Raises
94
+ ------
95
+ NetworkException
96
+ DESCRIPTION.
97
+ ApiException
98
+ DESCRIPTION.
99
+
100
+ Returns
101
+ -------
102
+ resp : TYPE
103
+ DESCRIPTION.
104
+
105
+ '''
106
+
107
+ try:
108
+ current_url_out = 'https://' + self.post_url + '/res.php'
109
+
110
+ async with httpx.AsyncClient(follow_redirects=True) as client:
111
+ resp = await client.get(current_url_out, params=kwargs)
112
+
113
+ if resp.status_code != 200:
114
+ raise NetworkException(f'bad response: {resp.status_code}')
115
+
116
+ resp = resp.content.decode('utf-8')
117
+
118
+ if 'ERROR' in resp:
119
+ raise ApiException(resp)
120
+
121
+ except httpx.RequestError as e:
122
+ raise NetworkException(e)
123
+
124
+ return resp