我在python中有一个代码,它用下面的代码将文件上传到服务器
with open(file_path, 'rb') as fp:
r = requests.Request('PUT', signedRequest, data=fp.read())
prepped = r.prepare()
s = requests.Session()
resp = s.send(prepped)在R中,我使用以下代码作为替换
PUT(url = signedRequest,
body = upload_file(path = file_path),verbose()
)但这是在抛出错误
HTTP/1.1 403 Forbidden在requestbin中,请求被接收为
对于Python
Cf-Connecting-Ip: ****
Host: requestb.in
Connect-Time: 1
Total-Route-Time: 0
Via: 1.1 vegur
Content-Length: 6481350
Connection: close
Cf-Ipcountry: US
X-Request-Id: f9b165cc-0f42-4eaa-8b40-2eb37a6ff1ca
Accept-Encoding: gzip
Cf-Ray: 346d734353e871df-ORD
Cf-Visitor: {"scheme":"http"}代表R
Cf-Connecting-Ip: ****
Content-Length: 6481350
User-Agent: libcurl/7.47.0 r-curl/2.3 httr/1.2.1
Total-Route-Time: 0
Via: 1.1 vegur
Connection: close
Cf-Ipcountry: US
Content-Type: text/csv
X-Request-Id: 0bfbf6ab-4658-4650-bd4d-e1e19ffdba91
Accept: application/json, text/xml, application/xml, */*
Connect-Time: 0
Accept-Encoding: gzip
Host: requestb.in
Cf-Ray: 346d6e90d70f54ec-ORD
Cf-Visitor: {"scheme":"http"}有什么建议吗?
发布于 2017-03-28 21:00:55
很难说服务器在抱怨什么,但是如果我们比较这两个请求,我们就会发现在内容类型和用户代理方面存在差异。
您可以使用
upload_file(path = file_path, type="")您也可以通过传递
user_agent("")作为PUT()的参数
https://stackoverflow.com/questions/43079427
复制相似问题