python - 谷歌驱动器下载不工作代码错误
问题描述
嘿,不知道为什么这不起作用。我的代码从我的谷歌驱动器下载一个文件,然后把它放在一个特定的目录中。不要不知道为什么会发生请帮忙
错误
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')
解决方案
计算的文件名将name = url.split("/")[-1]
包含?
windows 上不允许的内容。考虑删除或替换?
fromname
变量,甚至id
从 url 中提取和使用参数值作为文件名。
为了验证在第一步中,设置name
为静态值,如test-download
推荐阅读
- sql - 将日期显示为月份
- javascript - 这个项目如何使用(交互式3d商城地图)https://github.com/codrops/Interactive3DMallMap on react
- linux - mapfile 命令给我语法问题
- reactjs - Jest 和 React Native:如何模拟 AccessibilityInfo
- c++ - << 矩阵运算符的含义
- spring-boot - springBoot表中Map类型的列
- php - 从 Vanilla 论坛获取论坛文件
- nginx - Nginx 为两个 React 应用程序提供服务
- spyder - 从 spyder 的静态代码分析中获取 E1101 错误(“无成员”)
- java - java.lang.NoClassDefFoundError:无法初始化类 io.restassured.RestAssured