diff --git a/qqbot/qcontacts.py b/qqbot/qcontacts.py index 2dcc65e..2d2521a 100644 --- a/qqbot/qcontacts.py +++ b/qqbot/qcontacts.py @@ -36,7 +36,7 @@ def __str__(self): return self.shortRepr def GetMemberName(self, memberUin): - return self.members.get(memberUin, 'NEWBIE') + return self.members.get(memberUin, '##UNKNOWN') class QContacts: def __init__(self): diff --git a/qqbot/qqbot.py b/qqbot/qqbot.py index 5fe254a..1f905e0 100644 --- a/qqbot/qqbot.py +++ b/qqbot/qqbot.py @@ -10,7 +10,7 @@ import random, time, sys, subprocess from qconf import QConf -from utf8logger import INFO, WARN +from utf8logger import INFO, WARN, DEBUG from qsession import QLogin, QSession from qterm import QTermServer from common import Utf8Partition @@ -94,6 +94,7 @@ def fetchForever(self): contacts = self.fetch() except (QSession.Error, Exception): WARN(' fetchForever 方法出错') + DEBUG('', exc_info=True) else: yield Message('fetchcomplete', contacts=contacts) @@ -107,7 +108,7 @@ def onPollComplete(self, message): try: contact = self.Get(ctype, uin=fromUin)[0] except IndexError: - contact = QContact(ctype, uin=fromUin, name='NEWBIE', qq='') + contact = QContact(ctype, uin=fromUin, name='##UNKNOWN', qq='') if ctype == 'buddy': memberName = '' diff --git a/qqbot/qsession.py b/qqbot/qsession.py index 59c7ac8..74ee906 100644 --- a/qqbot/qsession.py +++ b/qqbot/qsession.py @@ -285,14 +285,23 @@ def fetchGroups(self, contacts, silence=True): INFO('登录 Step7 - 获取群列表') INFO('=' * 60) - result = self.smartRequest( - url = 'http://s.web2.qq.com/api/get_group_name_list_mask2', - data = { - 'r': JsonDumps({'vfwebqq':self.vfwebqq, 'hash':self.hash}) - }, - Referer = ('http://d1.web2.qq.com/proxy.html?v=20151105001&' - 'callback=1&id=2') - ) + for i in range(5): + result = self.smartRequest( + url = 'http://s.web2.qq.com/api/get_group_name_list_mask2', + data = { + 'r': JsonDumps({'vfwebqq':self.vfwebqq, 'hash':self.hash}) + }, + Referer = ('http://d1.web2.qq.com/proxy.html?v=20151105001&' + 'callback=1&id=2') + ) + if 'gmarklist' in result: + break + else: + ERROR('获取群列表出错,等待 3 秒后再次尝试一次') + time.sleep(3) + else: + CRITICAL('无法获取到群列表') + raise QSession.Error markDict = dict((d['uin'],d['markname']) for d in result['gmarklist']) @@ -476,12 +485,13 @@ def urlGet(self, url, data=None, **kw): except (requests.exceptions.SSLError, AttributeError): # by @staugur, @pandolia if self.session.verify: - self.session.verify = False + time.sleep(5) ERROR('无法和腾讯服务器建立私密连接,' ' 10 秒后将尝试使用非私密连接和腾讯服务器通讯。' '若您不希望使用非私密连接,请按 Ctrl+C 退出本程序。') time.sleep(10) - WARN('已开始尝试使用非私密连接和腾讯服务器通讯。') + WARN('开始尝试使用非私密连接和腾讯服务器通讯。') + self.session.verify = False requests.packages.urllib3.disable_warnings( requests.packages.urllib3.exceptions. InsecureRequestWarning diff --git a/qqbot/qterm.py b/qqbot/qterm.py index 8694a08..0cb23a6 100644 --- a/qqbot/qterm.py +++ b/qqbot/qterm.py @@ -92,7 +92,7 @@ def qterm(port): while True: front, resp = partition(resp) if resp: - RAWINPUT(front+'...') + RAWINPUT(front+'--More--') else: resp = front break diff --git a/qqbot/utf8logger.py b/qqbot/utf8logger.py index 9073ad7..e57c017 100644 --- a/qqbot/utf8logger.py +++ b/qqbot/utf8logger.py @@ -64,4 +64,5 @@ def RAWINPUT(msg): s = s.decode(sys.stdin.encoding).encode('utf8') return s -PRINT = lambda s: utf8Stdout.write(s + '\n') +def PRINT(s, end='\n'): + return utf8Stdout.write(s+end)