Skip to content

Commit

Permalink
fix: fetch captcha (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Apr 10, 2019
1 parent 8b100af commit 1c3b549
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/fateadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def __init__(self, app_id, app_key, usr_id, usr_key):

def calc_sign(self, usr_id, passwd, timestamp):
md5 = hashlib.md5()
md5.update(timestamp + passwd)
md5.update((timestamp + passwd).encode())
csign = md5.hexdigest()

md5 = hashlib.md5()
md5.update(usr_id + timestamp + csign)
md5.update((usr_id + timestamp + csign).encode())
csign = md5.hexdigest()
return csign

Expand Down
7 changes: 5 additions & 2 deletions wechatsogou/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time

import requests

from wechatsogou.const import agents, WechatSogouConst
from wechatsogou.exceptions import WechatSogouException, WechatSogouRequestsException, WechatSogouVcodeOcrException
from wechatsogou.five import must_str, quote
Expand Down Expand Up @@ -72,9 +73,11 @@ def __unlock_sogou(self, url, resp, session, unlock_callback=None, identify_imag
if unlock_callback is None:
unlock_callback = unlock_sogou_callback_example
millis = int(round(time.time() * 1000))
r_captcha = session.get('http://weixin.sogou.com/antispider/util/seccode.php?tc={}'.format(millis))
r_captcha = session.get('http://weixin.sogou.com/antispider/util/seccode.php?tc={}'.format(millis), headers={
'Referer': url,
})
if not r_captcha.ok:
raise WechatSogouRequestsException('WechatSogouAPI get img', resp)
raise WechatSogouRequestsException('WechatSogouAPI get img', r_captcha)

r_unlock = unlock_callback(url, session, resp, r_captcha.content, identify_image_callback)

Expand Down
6 changes: 6 additions & 0 deletions wechatsogou/filecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ def __init__(self, cache_dir='/tmp/wechatsogou-cache', default_timeout=300):
cache_dir是缓存目录
"""
super(WechatCache, self).__init__(cache_dir, default_timeout)

def get(self, key):
try:
return super(WechatCache, self).get(key)
except ValueError:
return None

0 comments on commit 1c3b549

Please sign in to comment.