Skip to content

Commit

Permalink
Fix badstatusline bug in sync_check
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Jul 16, 2017
1 parent 05255c4 commit bbcb817
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion itchat/components/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def get_head_img(self, userName=None, chatroomUserName=None, picDir=None):
'Ret': -1001, }})
if 'EncryChatRoomId' in chatroom:
params['chatroomid'] = chatroom['EncryChatRoomId']
params['chatroomid'] = params['chatroomid'] or chatroom['UserName']
params['chatroomid'] = params.get('chatroomid') or chatroom['UserName']
headers = { 'User-Agent' : config.USER_AGENT }
r = self.s.get(url, params=params, stream=True, headers=headers)
tempStorage = io.BytesIO()
Expand Down
18 changes: 17 additions & 1 deletion itchat/components/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import json, xml.dom.minidom
import copy, pickle, random
import traceback, logging
try:
from httplib import BadStatusLine
except ImportError:
from http.client import BadStatusLine

import requests
from pyqrcode import QRCode
Expand Down Expand Up @@ -292,7 +296,19 @@ def sync_check(self):
'synckey' : self.loginInfo['synckey'],
'_' : int(time.time() * 1000),}
headers = { 'User-Agent' : config.USER_AGENT }
r = self.s.get(url, params=params, headers=headers, timeout=config.TIMEOUT)
try:
r = self.s.get(url, params=params, headers=headers, timeout=config.TIMEOUT)
except requests.exceptions.ConnectionError as e:
try:
if not isinstance(e.args[0].args[1], BadStatusLine):
raise
# will return a package with status '0 -'
# and value like:
# 6f:00:8a:9c:09:74:e4:d8:e0:14:bf:96:3a:56:a0:64:1b:a4:25:5d:12:f4:31:a5:30:f1:c6:48:5f:c3:75:6a:99:93
# seems like status of typing, but before I make further achievement code will remain like this
return '2'
except:
raise
r.raise_for_status()
regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
pm = re.search(regx, r.text)
Expand Down
2 changes: 1 addition & 1 deletion itchat/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, platform

VERSION = '1.3.8'
VERSION = '1.3.9'
BASE_URL = 'https://login.weixin.qq.com'
OS = platform.system() # Windows, Linux, Darwin
DIR = os.getcwd()
Expand Down

0 comments on commit bbcb817

Please sign in to comment.