Skip to content
This repository was archived by the owner on Jun 29, 2026. It is now read-only.

Commit ddaf0d1

Browse files
committed
fix failback bug
1 parent 3ac68e2 commit ddaf0d1

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

geetest/geetest.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!coding:utf8
2-
import string
32
import urllib2
43
import random
54
import json
65
from hashlib import md5
76
from urllib import urlencode
87

98

10-
VERSION = "3.0.0"
9+
VERSION = "3.0.1"
1110

1211

1312
class GeetestLib(object):
@@ -25,11 +24,10 @@ class GeetestLib(object):
2524
REGISTER_HANDLER = "/register.php"
2625
VALIDATE_HANDLER = "/validate.php"
2726

28-
2927
def __init__(self, captcha_id, private_key):
30-
self.private_key = private_key #私钥
31-
self.captcha_id = captcha_id #公钥
32-
self.sdk_version = VERSION #SDK版本
28+
self.private_key = private_key
29+
self.captcha_id = captcha_id
30+
self.sdk_version = VERSION
3331

3432
def pre_process(self):
3533
"""
@@ -56,7 +54,8 @@ def _make_fail_challenge(self):
5654
def _make_response_format(self, success=1, challenge=None):
5755
if not challenge:
5856
challenge = self._make_fail_challenge()
59-
string_format = json.dumps({'success': success, 'gt':self.captcha_id ,'challenge': challenge})
57+
string_format = json.dumps(
58+
{'success': success, 'gt':self.captcha_id ,'challenge': challenge})
6059
return string_format
6160

6261
def _register_challenge(self):
@@ -85,7 +84,7 @@ def success_validate(self, challenge, validate, seccode):
8584
return self.FAIL_RES
8685
if not self._check_result(challenge, validate):
8786
return self.FAIL_RES
88-
validate_url = "{api_url}{handler}".format(
87+
validate_url = "{api_url}{handler}".format(
8988
api_url=self.API_URL, handler=self.VALIDATE_HANDLER)
9089
query = {
9190
"seccode": seccode,
@@ -98,7 +97,6 @@ def success_validate(self, challenge, validate, seccode):
9897
else:
9998
return self.FAIL_RES
10099

101-
102100
def _post_values(self, apiserver, data):
103101
req = urllib2.Request(apiserver)
104102
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
@@ -121,16 +119,17 @@ def failback_validate(self, challenge, validate, seccode):
121119
return self.FAIL_RES
122120
validate_str = validate.split('_')
123121
encode_ans = validate_str[0]
124-
encode_fbii = validate_str[1] #_fbii : Full Bg Img Index
122+
encode_fbii = validate_str[1]
125123
encode_igi = validate_str[2]
126-
decode_ans = self.decode_response(challenge, encode_ans)
127-
decode_fbii = self.decode_response(challenge, encode_fbii)
128-
decode_igi = self.decode_response(challenge, encode_igi) #_igi : Img Grp Index
129-
validate_result = self._validate_fail_image(decode_ans, decode_fbii, decode_igi)
124+
decode_ans = self._decode_response(challenge, encode_ans)
125+
decode_fbii = self._decode_response(challenge, encode_fbii)
126+
decode_igi = self._decode_response(challenge, encode_igi)
127+
validate_result = self._validate_fail_image(
128+
decode_ans, decode_fbii, decode_igi)
130129
return validate_result
131130

132131
def _check_para(self, challenge, validate, seccode):
133-
return bool(challenge.strip()) and bool(validate.strip()) and bool(seccode.strip())
132+
return (bool(challenge.strip()) and bool(validate.strip()) and bool(seccode.strip()))
134133

135134
def _validate_fail_image(self, ans, full_bg_index , img_grp_index):
136135
thread = 3

0 commit comments

Comments
 (0)