![](/img/trans.png)
[英]python web scraping: onclick ajax request returns nothing with status 200
[英]Python post request response status is "200" but when nothing is getting posted in the desired page
我正在嘗試通過 python http 發布方法上傳(發送)文件。像這樣
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)似乎不存在。如何解決這個問題? 有沒有其他方法可以上傳 python 中的文件?
根據文檔, 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 但沒有上傳文件的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.