From fc81ba6e53a8c5f7ddeb7edfc8e6e5e7dedde924 Mon Sep 17 00:00:00 2001 From: LittleCoder Date: Fri, 3 Nov 2017 09:38:44 +0800 Subject: [PATCH] Fix big file upload --- itchat/components/login.py | 11 +++++++---- itchat/components/messages.py | 2 +- itchat/config.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/itchat/components/login.py b/itchat/components/login.py index 9aa963a4..b542027e 100644 --- a/itchat/components/login.py +++ b/itchat/components/login.py @@ -127,8 +127,8 @@ def check_login(self, uuid=None): uuid = uuid or self.uuid url = '%s/cgi-bin/mmwebwx-bin/login' % config.BASE_URL localTime = int(time.time()) - params = 'loginicon=true&uuid=%s&tip=0&r=%s&_=%s' % ( - uuid, localTime / 1579, localTime) + params = 'loginicon=true&uuid=%s&tip=1&r=%s&_=%s' % ( + uuid, int(-localTime / 1579), localTime) headers = { 'User-Agent' : config.USER_AGENT } r = self.s.get(url, params=params, headers=headers) regx = r'window.code=(\d+)' @@ -185,12 +185,15 @@ def process_login_info(core, loginContent): return True def web_init(self): - url = '%s/webwxinit?r=%s' % (self.loginInfo['url'], int(time.time())) + url = '%s/webwxinit' % self.loginInfo['url'] + params = { + 'r': int(-time.time() / 1579), + 'pass_ticket': self.loginInfo['pass_ticket'], } data = { 'BaseRequest': self.loginInfo['BaseRequest'], } headers = { 'ContentType': 'application/json; charset=UTF-8', 'User-Agent' : config.USER_AGENT, } - r = self.s.post(url, data=json.dumps(data), headers=headers) + r = self.s.post(url, params=params, data=json.dumps(data), headers=headers) dic = json.loads(r.content.decode('utf-8', 'replace')) # deal with login info utils.emoji_formatter(dic['User'], 'NickName') diff --git a/itchat/components/messages.py b/itchat/components/messages.py index b0f10b20..5f500420 100644 --- a/itchat/components/messages.py +++ b/itchat/components/messages.py @@ -359,7 +359,7 @@ def upload_chunk_file(core, fileDir, fileSymbol, fileSize, else: files['chunk'], files['chunks'] = (None, str(chunk)), (None, str(chunks)) headers = { 'User-Agent' : config.USER_AGENT } - return requests.post(url, files=files, headers=headers) + return core.s.post(url, files=files, headers=headers) def send_file(self, fileDir, toUserName=None, mediaId=None, file_=None): logger.debug('Request to send a file(mediaId: %s) to %s: %s' % ( diff --git a/itchat/config.py b/itchat/config.py index 9d2aa923..36ca488b 100644 --- a/itchat/config.py +++ b/itchat/config.py @@ -1,6 +1,6 @@ import os, platform -VERSION = '1.3.9' +VERSION = '1.3.10' BASE_URL = 'https://login.weixin.qq.com' OS = platform.system() # Windows, Linux, Darwin DIR = os.getcwd()