我正在使用Python的Requests库将PDF发布到文档存储,然后在签名过程中使用上传的PDF。但是,当使用Python (而不是CURL)上传PDF时,签名环境不起作用。在比较不同的文件时,我发现Requests会将一些数据添加到PDF中:
--ca9a0d04edf64b3395e62c72c7c143a5
Content-Disposition: form-data; name="LoI.pdf"; filename="LoI.pdf"
%%Original PDF goes here%%
--ca9a0d04edf64b3395e62c72c7c143a5--这些数据完全可以被不同的PDF阅读器接受,但不能被签名API接受。有没有办法防止请求将这些数据添加到PDF中?我使用了以下代码:
myfile = request.FILES['myfile']
url = %%documentstoreURL%%
resp = requests.request('post', url, files={myfile.name:myfile}, headers={'Content-Type':'application/pdf'}, auth=(%%auth details%%))谢谢!
发布于 2017-05-01 21:50:38
您使用curl将文件作为二进制数据发送,但将其附加在请求中。
我仔细阅读了源代码,我相信resp = requests.request('post', url, data={myfile.name:myfile}, headers={'Content-Type':'application/pdf'}, auth=(%%auth details%%)) (data而不是files)将避免多部分编码。
至少,它应该以不同的方式被破坏。
发布于 2017-05-01 22:37:56
在正确的方向上,我找到了一个基于Python requests - POST data from a file的工作解决方案
最后,我这样做了:
myfile = request.FILES['myfile']
payload = request.FILES['myfile'].read()
headers = {'content-type': 'application/pdf'}
url = "%%DocumentServiceURL"
r = requests.post(url, auth=(%%auth_details%%), data=payload, verify=False, headers=headers)https://stackoverflow.com/questions/43719734
复制相似问题