Python Requests Multipart HTTP POST

前端 未结 3 390
抹茶落季
抹茶落季 2021-01-03 05:32

I was wondering how do you translate something like this using Python Requests? In urllib2, you can manually manipulate the data that is being sent over the wire to the API

3条回答
  •  别那么骄傲
    2021-01-03 06:18

     import requests
    
     import urllib
    
     def upload_creative(self, account_id, file_path):
    
        files = [('userfile', (file_path, open(file_path, 'rb'), "image/jpeg" ))]
    
        url = self._resolve_url('/a/creative/uploadcreative')
    
        url =  url + "?"  +  urlib.urlencode(account_id=account_id)
    
        reuests.post(url, files=files)
    

提交回复
热议问题