url 鏈接是指向我試圖向下引導的 Web 檔案(xlsb 檔案)的直接鏈接。下面的代碼沒有錯誤,檔案似乎是在路徑中創建的,但是一旦我嘗試打開它,excel 上就會彈出損壞的檔案訊息。回應狀態是 400,所以這是一個錯誤的請求。對此有何建議?
url = 'http://rigcount.bakerhughes.com/static-files/55ff50da-ac65-410d-924c-fe45b23db298'
file_name = r'local path with xlsb extension'
with open(file_name, "wb") as file:
response = requests.request(method="GET", url=url)
file.write(response.content)
uj5u.com熱心網友回復:
似乎對我有用。試試這個:
from requests import get
url = 'http://rigcount.bakerhughes.com/static-files/55ff50da-ac65-410d-924c-fe45b23db298'
# make HTTP request to fetch data
r = get(url)
# check if request is success
r.raise_for_status()
# write out byte content to file
with open('out.xlsb', 'wb') as out_file:
out_file.write(r.content)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/325083.html
上一篇:SqliteexecuteSql不回傳ResultSet
下一篇:如何多次上傳檔案?
