python requests file upload

后端 未结 4 691
醉梦人生
醉梦人生 2020-11-22 13:20

I\'m performing a simple task of uploading a file using Python requests library. I searched Stack Overflow and no one seemed to have the same problem, namely, that the file

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 13:27

    (2018) the new python requests library has simplified this process, we can use the 'files' variable to signal that we want to upload a multipart-encoded file

    url = 'http://httpbin.org/post'
    files = {'file': open('report.xls', 'rb')}
    
    r = requests.post(url, files=files)
    r.text
    

提交回复
热议问题