def submit(self, captcha, captchaType="file", match=None):
req = get_request()
#: Raise timeout threshold
req.c.setopt(pycurl.LOW_SPEED_TIME, 80)
try:
#@NOTE: Workaround multipart-post bug in HTTPRequest.py
if re.match("^\w*$", self.config.get('password')):
multipart = True
data = (pycurl.FORM_FILE, captcha)
else:
multipart = False
with open(captcha, 'rb') as f:
data = f.read()
data = base64.b64encode(data)
res = self.load(self.SUBMIT_URL,
post={'action': "UPLOADCAPTCHA",
'username': self.config.get('username'),
'password': self.config.get('password'), 'file': data},
multipart=multipart,
req=req)
finally:
req.close()
if res.startswith("ERROR"):
raise ImageTyperzException(res)
else:
data = res.split('|')
if len(data) == 2:
ticket, result = data
else:
raise ImageTyperzException("Unknown response: %s" % res)
return ticket, result
评论列表
文章目录