使用python在sharepoint上上载文件会导致上载的文件在内容中保留标头

2024-09-27 21:26:35 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用我的脚本提交post请求时,我不会对数据进行编码并按如下方式准备post请求:

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)

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

^{pr2}$

但是通过firefox上传的文件没有这些头文件。我想我需要调用一个sharepoint函数(如果有一个restapi来处理文件)来在文件上传后处理它,或者如果python请求中有一个方法可以像本文中提到的那样处理这些头文件:stackoverflow post


Tags: 文件数据脚本jsontrueverbose头文件application
2条回答

不要使用多部分/表单数据 即 在curl世界中,使用“data binary”@测试文件.xls“而不是-F upload=”@测试文件.xls““

如果它在Firefox上运行良好,那么它通常也可以与python请求模块一起工作。在

您是否仔细检查了与“post-a-multipart-encoded-file”相关的requests docs?在

在火狐:火狐您可以右键单击请求,然后选择“复制为卷曲”以进行双重检查。。。在

相关问题 更多 >

    热门问题