gpt4 book ai didi

python - 使用 python 脚本下载文件时出现错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:15:58 24 4
gpt4 key购买 nike

在python3.4中使用wget下载

import wget
url = "http://api.example.com/tracks/41078914/stream?client_id=d97babdd9960f87d30831e0eb9d"
file = wget.download(url)
print(file)

出现此类错误:-

Traceback (most recent call last):
File "/home/poison/PycharmProjects/pytho_pro/B1.py", line 10, in <module>
file = wget.download(url)
File "/usr/local/lib/python3.4/dist-packages/wget.py", line 319, in download
filename = filename_fix_existing(filename)
File "/usr/local/lib/python3.4/dist-packages/wget.py", line 77, in filename_fix_existing
name, ext = filename.rsplit('.', 1)
ValueError: need more than 1 value to unpack

最佳答案

无法通过 url 或 HTTP header 检索文件名。我建议自己设置输出文件名:

import wget
url = "http://api.example.com/tracks/41078914/stream?client_id=d97babdd9960f87d30831e0eb9d"
file = wget.download(url,out="myFile.mp3")
print(file)

关于python - 使用 python 脚本下载文件时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25000992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com