Upload Image using POST form data in Python-requests

前端 未结 7 1781
醉话见心
醉话见心 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:34

    Use this snippet

    import os
    import requests
    url = 'http://host:port/endpoint'
    with open(path_img, 'rb') as img:
      name_img= os.path.basename(path_img)
      files= {'image': (name_img,img,'multipart/form-data',{'Expires': '0'}) }
      with requests.Session() as s:
        r = s.post(url,files=files)
        print(r.status_code)
    

提交回复
热议问题