diff --git a/itchat/components/contact.py b/itchat/components/contact.py index 3026ba5c..70609ed3 100644 --- a/itchat/components/contact.py +++ b/itchat/components/contact.py @@ -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() diff --git a/itchat/components/login.py b/itchat/components/login.py index 6e64fbae..9aa963a4 100644 --- a/itchat/components/login.py +++ b/itchat/components/login.py @@ -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 @@ -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) diff --git a/itchat/config.py b/itchat/config.py index cc785e7f..9d2aa923 100644 --- a/itchat/config.py +++ b/itchat/config.py @@ -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()