首页 > 解决方案 > 谷歌驱动器下载不工作代码错误

问题描述

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

错误

在此处输入图像描述

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')

标签: pythondownload

解决方案


计算的文件名将name = url.split("/")[-1]包含?windows 上不允许的内容。考虑删除或替换?fromname变量,甚至id从 url 中提取和使用参数值作为文件名。

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


推荐阅读