谷歌硬盘下载不工作代码错误

2024-04-25 06:11:08 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,我不知道为什么这不起作用。我的代码从我的谷歌硬盘下载一个文件,然后把它放在一个特定的目录中。不知道为什么会这样请帮忙

错误

enter image description here

import os
import requests
def download(url):
    directory = 'C:\Users\IEUser\AppData\Roaming'
    name = url.split("/")[-1]
    file_name = os.path.join(directory, name)
    get_response = requests.get(url)
    with open(file_name, "wb") as out_file:
        out_file.write(get_response.content)

download('http://drive.google.com/u/0/uc?id=1A2Q3C2VN_8d3AHuNnWX0ZGFmhaeNHNL8&export=download')

1条回答
网友
1楼 · 发布于 2024-04-25 06:11:08

name = url.split("/")[-1]计算的文件名将包含在windows上不允许的?。考虑从^ {< CD4> }变量中删除或替换^ {CD2> },甚至从URL中提取并使用^ {< CD5> }参数值作为文件名。

为了验证这一点,在第一步中,将name设置为静态值,如test-download

相关问题 更多 >