【发布时间】:2021-10-02 10:55:26
【问题描述】:
import os
import requests
def download_file(download_url: str, filename: str):
"""
Download resume pdf file from storage
@param download_url: URL of reusme to be downloaded
@type download_url: str
@param filename: Name and location of file to be stored
@type filename: str
@return: None
@rtype: None
"""
file_request = requests.get(download_url)
with open(f'{filename}.pdf', 'wb+') as file:
file.write(file_request.content)
cand_id = "101"
time_current = "801"
file_location = f"{cand_id}_{time_current}"
download_file("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", file_location)
cand_id = "201"
time_current = "901"
download_file("https://drive.google.com/file/d/0B1HXnM1lBuoqMzVhZjcwNTAtZWI5OS00ZDg3LWEyMzktNzZmYWY2Y2NhNWQx/view?hl=en&resourcekey=0-5DqnTtXPFvySMiWstuAYdA", file_location)
----------
- 第一个文件运行良好(即 101_801.pdf)
- 但第二个无法在任何 pdf 阅读器中打开(即 201_901.pdf)(错误:我们无法打开此文件)。
- 我的理解是我无法正确读写文件 从对所有人开放的驱动器。如何读取和写入该文件?
- 我可以使用 google drive API,但是如果没有,我们可以有更好的解决方案吗? 用那个?
【问题讨论】:
标签: python-3.x python-requests google-drive-api file-writing