为什么从web下载excel文件失败?



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) 

似乎对我有用。试一下:

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)

相关内容

  • 没有找到相关文章

最新更新