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

时间:2014-07-28 17:37:34

标签: python wget python-3.4

在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

1 个答案:

答案 0 :(得分:1)

无法通过网址或HTTP标头检索文件名。我建议你自己设置输出文件名:

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