Thursday, 15 April 2010

Upload Image using POST form data in Python-requests -


I am working with the wechat API ... here I upload an image to the wechat server using this API

  url = 'http://file.api.wechat.com/cgi-bin/media/upload?access_token=%s&type=image'%access_token files = {' file ': (File name, open (file path,' rb '),' content-type ':' image / jpeg ',' content-length ': l} r = requests.post (url, files = files)  

I am not able to post data

Wechat API Doctor:

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

Translate the above command to Python:

  import request url = 'http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&; Type = TYPE' files = {'media': open ('Test.jpg', 'rb')} request.post (url, files = files)  

No comments:

Post a Comment