使用python请求的多部分POST

use*_*337 2 python python-2.7 mime-types python-requests

我正在使用python包请求进行多部分POST.我使用xlrd更改Excel文件中的某些值保存,然后在多部分POST中发送它.当我在我的Mac上本地运行它时,这工作正常,但是当我将代码放在远程机器上并发出相同的请求时,正文内容类型为空白,而本地内容类型为application/vnd.ms-excel.所以我的问题是,有没有办法使用python请求强制执行内容类型,以便在这种情况下,正文内容类型是application/vnd.ms-excel.抱歉无法发布任何代码,因为我没有在这台机器上.

Luk*_*asa 8

files参数接受元组键的字典,格式如下:

files = {'name': (<filename>, <file object>, <content type>, <per-part headers>)}
Run Code Online (Sandbox Code Playgroud)

在您的具体情况下,您可以这样写:

files = {'file': ('filename.xls', open('filename.xls'), 'application/vnd.ms-excel', {})}
Run Code Online (Sandbox Code Playgroud)

这应该工作正常.