Skip to content

Commit bbcb817

Browse files
committed
Fix badstatusline bug in sync_check
1 parent 05255c4 commit bbcb817

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

itchat/components/contact.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def get_head_img(self, userName=None, chatroomUserName=None, picDir=None):
406406
'Ret': -1001, }})
407407
if 'EncryChatRoomId' in chatroom:
408408
params['chatroomid'] = chatroom['EncryChatRoomId']
409-
params['chatroomid'] = params['chatroomid'] or chatroom['UserName']
409+
params['chatroomid'] = params.get('chatroomid') or chatroom['UserName']
410410
headers = { 'User-Agent' : config.USER_AGENT }
411411
r = self.s.get(url, params=params, stream=True, headers=headers)
412412
tempStorage = io.BytesIO()

itchat/components/login.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import json, xml.dom.minidom
44
import copy, pickle, random
55
import traceback, logging
6+
try:
7+
from httplib import BadStatusLine
8+
except ImportError:
9+
from http.client import BadStatusLine
610

711
import requests
812
from pyqrcode import QRCode
@@ -292,7 +296,19 @@ def sync_check(self):
292296
'synckey' : self.loginInfo['synckey'],
293297
'_' : int(time.time() * 1000),}
294298
headers = { 'User-Agent' : config.USER_AGENT }
295-
r = self.s.get(url, params=params, headers=headers, timeout=config.TIMEOUT)
299+
try:
300+
r = self.s.get(url, params=params, headers=headers, timeout=config.TIMEOUT)
301+
except requests.exceptions.ConnectionError as e:
302+
try:
303+
if not isinstance(e.args[0].args[1], BadStatusLine):
304+
raise
305+
# will return a package with status '0 -'
306+
# and value like:
307+
# 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
308+
# seems like status of typing, but before I make further achievement code will remain like this
309+
return '2'
310+
except:
311+
raise
296312
r.raise_for_status()
297313
regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
298314
pm = re.search(regx, r.text)

itchat/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os, platform
22

3-
VERSION = '1.3.8'
3+
VERSION = '1.3.9'
44
BASE_URL = 'https://login.weixin.qq.com'
55
OS = platform.system() # Windows, Linux, Darwin
66
DIR = os.getcwd()

0 commit comments

Comments
 (0)