-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaptcha2upload.py
167 lines (160 loc) · 7.67 KB
/
captcha2upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from os.path import exists
from requests import post, get
from time import sleep
class CaptchaUpload:
def __init__(self, key, log=None, waittime=None):
self.settings = {"url_request": "http://azcaptcha.com/in.php",
"url_response": "http://azcaptcha.com/res.php",
"key": key}
if log:
self.log = log
self.logenabled = True
else:
self.logenabled = False
if waittime:
self.waittime = waittime
else:
self.waittime = 10
def getbalance(self):
"""
This request need for get balance
:return: <YOURBALANCE> OK | 1 ERROR!
"""
fullurl = "%s?action=getbalance&key=%s" % (
self.settings['url_response'], self.settings['key'])
request = get(fullurl)
if "." in request.text:
if self.logenabled:
self.log.info("[AZCaptchaUpload] Balance: %s" % request.text)
return request.text
elif request.text == "ERROR_KEY_DOES_NOT_EXIST":
if self.logenabled:
self.log.error("[AZCaptchaUpload] You used the wrong key in "
"the query")
return 1
elif request.text == "ERROR_WRONG_ID_FORMAT":
if self.logenabled:
self.log.error("[AZCaptchaUpload] Wrong format ID CAPTCHA. "
"ID must contain only numbers")
return 1
def getresult(self, id):
"""
This function return the captcha solved
:param id: id captcha returned by upload
:return: <captchaword> OK | 1 ERROR!
"""
if self.logenabled:
self.log.info("[AZCaptchaUpload] Wait %s second.." % self.waittime)
sleep(self.waittime)
fullurl = "%s?key=%s&action=get&id=%s" % (self.settings['url_response'],
self.settings['key'], id)
if self.logenabled:
self.log.info("[AZCaptchaUpload] Get Captcha solved with id %s"
% id)
request = get(fullurl)
if request.text.split('|')[0] == "OK":
return request.text.split('|')[1]
elif request.text == "CAPCHA_NOT_READY":
if self.logenabled:
self.log.error("[AZCaptchaUpload] CAPTCHA is being solved, "
"repeat the request several seconds later, wait "
"another %s seconds" % self.waittime)
return self.getresult(id)
elif request.text == "ERROR_KEY_DOES_NOT_EXIST":
if self.logenabled:
self.log.error("[AZCaptchaUpload] You used the wrong key in "
"the query")
return 1
elif request.text == "ERROR_WRONG_ID_FORMAT":
if self.logenabled:
self.log.error("[AZCaptchaUpload] Wrong format ID CAPTCHA. "
"ID must contain only numbers")
return 1
elif request.text == "ERROR_CAPTCHA_UNSOLVABLE":
if self.logenabled:
self.log.error("[AZCaptchaUpload] Captcha could not solve "
"three different employee. Funds for this "
"captcha not")
return 1
def solve(self, pathfile):
"""
This function upload read, upload and is the wrapper for solve
the captcha
:param pathfile: path of image
:return: <captchaword> OK | 1 ERROR!
"""
if exists(pathfile):
files = {'file': open(pathfile, 'rb')}
payload = {'key': self.settings['key'], 'method': 'post'}
if self.logenabled:
self.log.info("[AZCaptchaUpload] Uploading to 2Captcha.com..")
request = post(self.settings['url_request'], files=files,
data=payload)
if request.ok:
if request.text.split('|')[0] == "OK":
if self.logenabled:
self.log.info("[AZCaptchaUpload] Upload Ok")
return self.getresult(request.text.split('|')[1])
elif request.text == "ERROR_WRONG_USER_KEY":
if self.logenabled:
self.log.error("[AZCaptchaUpload] Wrong 'key' parameter"
" format, it should contain 32 symbols")
return 1
elif request.text == "ERROR_KEY_DOES_NOT_EXIST":
if self.logenabled:
self.log.error("[AZCaptchaUpload] The 'key' doesn't "
"exist")
return 1
elif request.text == "ERROR_ZERO_BALANCE":
if self.logenabled:
self.log.error("[AZCaptchaUpload] You don't have money "
"on your account")
return 1
elif request.text == "ERROR_NO_SLOT_AVAILABLE":
if self.logenabled:
self.log.error("[AZCaptchaUpload] The current bid is "
"higher than the maximum bid set for "
"your account.")
return 1
elif request.text == "ERROR_ZERO_CAPTCHA_FILESIZE":
if self.logenabled:
self.log.error("[AZCaptchaUpload] CAPTCHA size is less"
" than 100 bites")
return 1
elif request.text == "ERROR_TOO_BIG_CAPTCHA_FILESIZE":
if self.logenabled:
self.log.error("[AZCaptchaUpload] CAPTCHA size is more"
" than 100 Kbites")
return 1
elif request.text == "ERROR_WRONG_FILE_EXTENSION":
if self.logenabled:
self.log.error("[AZCaptchaUpload] The CAPTCHA has a "
"wrong extension. Possible extensions "
"are: jpg,jpeg,gif,png")
return 1
elif request.text == "ERROR_IMAGE_TYPE_NOT_SUPPORTED":
if self.logenabled:
self.log.error("[AZCaptchaUpload] The server cannot "
"recognize the CAPTCHA file type.")
return 1
elif request.text == "ERROR_IP_NOT_ALLOWED":
if self.logenabled:
self.log.error("[AZCaptchaUpload] The request has sent "
"from the IP that is not on the list of"
" your IPs. Check the list of your IPs "
"in the system.")
return 1
elif request.text == "IP_BANNED":
if self.logenabled:
self.log.error("[AZCaptchaUpload] The IP address you're"
" trying to access our server with is "
"banned due to many frequent attempts "
"to access the server using wrong "
"authorization keys. To lift the ban, "
"please, contact our support team via "
"email: [email protected]")
return 1
else:
if self.logenabled:
self.log.error("[AZCaptchaUpload] File %s not exists" % pathfile)
return 1