【发布时间】:2019-05-12 14:00:19
【问题描述】:
我有一个需要上传的 zip 文件。当我使用 CURL 命令时,它正在上传它,但是当我使用 Python 请求尝试相同时,我得到HTTP 405 Method Not Allowed。
zip 文件通常在 500kb 左右。
卷曲命令 -
curl -u<username>:<password> -T /log/system/check/index.zip "<target URL>"
Python 脚本(尝试了 2 种不同的方法) -
1:
import requests
files = {'file': open('/log/system/check/index.zip', 'rb')}
r = requests.post(url, files=files, auth=('<username>', '<password>'))
2:
import requests
fileobj = open('/log/system/check/index.zip', 'rb')
r = requests.post(url, auth=('<username>', '<password>'), files={"archive": ("index.zip", fileobj)})
我是否遗漏了一些明显的东西?
【问题讨论】:
-
那么
curl命令成功了吗?curl联机帮助页说明了-T:If this is used on an HTTP(S) server, the PUT command will be used.因此,curl 使用的是PUT,而不是POST。您的端点是否允许POST? -
我现在尝试使用 PUT 并看到错误 -
Tunnel connection failed: 503 Service Unavailable',不确定是否需要任何代理 -
但为了清楚起见,您列出的
curl命令可以正常工作吗? -
是的,它工作得非常好。它正在上传文件。
标签: python curl python-requests