我正试图像这样通过python method.Something上传(发送)一个文件
import requests
#file = open('dummy.tar','rb')
with open('dummy.tar','rb') as f:
r = requests.post('http://artifact.swf.daimler.com/artifactory/apricotbscqal/build/rusi_delta_lb/', files={'dummy.tar': f})
if r.ok:
print(r.status_code)
print("Upload completed successfully!")
else:
print("Something went wrong!")状态显示为200,但当我检查目标链接时,这个特定的文件(dummy.tar)似乎不是present.How来解决这个问题吗?在python中还有其他上传文件的方法吗?
发布于 2022-08-22 15:36:25
根据文档,files参数是一个字典,其中的键是html表单字段名。例如,如果表单中有一个filename字段,如下所示:
<input type="file" id="myFile" name="filename">那么您的代码应该是:
import requests
with open('dummy.tar','rb') as f:
r = requests.post('http://artifact.swf.daimler.com/artifactory/apricotbscqal/build/rusi_delta_lb/', files={'filename': f})
if r.ok:
print(r.status_code)
print("Upload completed successfully!")
else:
print("Something went wrong!")这可能是你获得状态200但没有上传文件的原因。
https://stackoverflow.com/questions/73447330
复制相似问题