为什么请求无法从网络下载 excel 文件?
Why request fails to download an excel file from web?
url link 是直接 link 到我试图下载的网络文件(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)
似乎对我有用。试试这个:
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)
url link 是直接 link 到我试图下载的网络文件(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)
似乎对我有用。试试这个:
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)