使用python在sharepoint上传文件会导致上传文件在内容中保留标题

ema*_*mad 8 python sharepoint http-headers

当我使用我的脚本提交帖子请求时,我不对数据进行编码并准备帖子请求:

postheader.update({'Accept':'application/json; odata=verbose','Content-Type':'application/json; odata=verbose', 'X-RequestDigest':formdigestvalue, 'binaryStringRequestBody':'true'})

filetoupload = {'file':(filename, open(filename, 'rb'), 'application/vnd.openxmlformats-officedocument.presentationml.presentation')}
posturl = projectConfig.sharepointurl + "/_api/web/getfolderbyserverrelativeurl('Shared Documents/release_doc/"+project+"')/files/add(url='"+filename+"', overwrite='true')"
response = requests.post(posturl, headers=postheader, files=filetoupload, cookies=postcookies)
Run Code Online (Sandbox Code Playgroud)

我看了一下我使用我的脚本上传的文件,它还在内容中附加了以下标题:

--6ab0a06f1ddc432186194dd48355eac1
Content-Disposition: form-data; name="ZZZ Technology Guide.pptx"; filename="ZZZ Technology Guide.pptx"
Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation

<file content>
--6ab0a06f1ddc432186194dd48355eac1--
Run Code Online (Sandbox Code Playgroud)

但是,通过firefox上传的文件没有这些标头.我想我需要调用一个sharepoint函数(如果有一个REST API那样做)来处理文件上传之后,或者如果python请求中有一个方法可以处理这些文件中提到的这些文件:stackoverflow帖子

A S*_*ANI 0

如果它在 Firefox 上工作正常,那么它通常也可以在 python requests 模块上工作。

您是否仔细检查了与“post-a-multipart-encoded-file”相关的请求文档?

在 Firefox:firebug 的网络选项卡下,您可以右键单击该请求,然后选择“复制为 cURL”以进行双重检查...

  • 这应该是一条评论 (2认同)