Upload Image using POST form data in Python-requests

前端 未结 7 1740
醉话见心
醉话见心 2020-11-27 04:16

I\'m working with wechat APIs ... here I\'ve to upload an image to wechat\'s server using this API http://admin.wechat.com/wiki/index.php?title=Transferring_Multimedia_Files

相关标签:
7条回答
  • 2020-11-27 04:41

    From wechat api doc:

    curl -F media=@test.jpg "http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"
    

    Translate the command above to python:

    import requests
    url = 'http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE'
    files = {'media': open('test.jpg', 'rb')}
    requests.post(url, files=files)
    
    0 讨论(0)
提交回复
热议问题