Git Product home page Git Product logo

Comments (2)

littlecodersh avatar littlecodersh commented on May 28, 2024 1

@pcloth 这是我们这里程序的bug
不过我不用python3只能粗略的先帮你改一下,更新程序版本的事情要交给@chyroc

解决方案如下
修改一下D:\Anaconda3\lib\site-packages\itchat\client.py__upload_file内容为:

def __upload_file(self, fileDir, isPicture=False):
    if not tools.check_file(fileDir): return
    url = 'https://file%s.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' % (
        '2' if '2' in self.loginInfo['url'] else '')
    # save it on server
    fileSize = str(os.path.getsize(fileDir))
    cookiesList = {name: data for name, data in self.s.cookies.items()}
    fileType = mimetypes.guess_type(fileDir)[0] or 'application/octet-stream'
    files = {
        'id': (None, 'WU_FILE_0'),
        'name': (None, os.path.basename(fileDir)),
        'type': (None, fileType),
        'lastModifiedDate': (None, time.strftime('%a %b %d %Y %H:%M:%S GMT+0800 (CST)')),
        'size': (None, fileSize),
        'mediatype': (None, 'pic' if isPicture else 'doc'),
        'uploadmediarequest': (None, json.dumps({
            'BaseRequest': {k: v.decode('ascii') for k, v in self.loginInfo['BaseRequest'].items()},
            'ClientMediaId': int(time.time()),
            'TotalLen': fileSize,
            'StartPos': 0,
            'DataLen': fileSize,
            'MediaType': 4,
        }, separators=(',', ':'))),
        'webwx_data_ticket': (None, cookiesList['webwx_data_ticket']),
        'pass_ticket': (None, 'undefined'),
        'filename': (os.path.basename(fileDir), open(fileDir, 'rb'), fileType),
    }
    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36'
    }
    r = self.s.post(url, files=files, headers=headers)
    return json.loads(r.text)['MediaId']

通过测试的程序

#!python3
import itchat

itchat.auto_login()
itchat.send('@[email protected]')

from itchat.

littlecodersh avatar littlecodersh commented on May 28, 2024

完成更新:Fix upload file bug

from itchat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.