AttributeError:“模块"对象没有属性"urlretrieve" [英] AttributeError: 'module' object has no attribute 'urlretrieve'
本文介绍了AttributeError:“模块"对象没有属性"urlretrieve"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个程序,该程序将从网站上下载mp3,然后将它们加入在一起,但是每当我尝试下载文件时,都会出现此错误:
I am trying to write a program that will download mp3's off of a website then join them together but whenever I try to download the files I get this error:
Traceback (most recent call last):
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 214, in <module> main()
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 209, in main getMp3s()
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 134, in getMp3s
raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")
AttributeError: 'module' object has no attribute 'urlretrieve'
导致此问题的行是
raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")
推荐答案
在使用Python 3时,不再有urllib模块.它已分为几个模块.
As you're using Python 3, there is no urllib module anymore. It has been split into several modules.
这等同于urlretrieve:
This would be equivalent to urlretrieve:
import urllib.request
data = urllib.request.urlretrieve("http://...")
urlretrieve的行为与Python 2.x完全相同,因此可以正常工作.
urlretrieve behaves exactly the same way as it did in Python 2.x, so it'll work just fine.
基本上:
-
urlretrieve
将文件保存到临时文件并返回元组(filename, headers)
-
urlopen
返回一个Request
对象,该对象的read
方法返回一个包含文件内容的字节串
urlretrieve
saves the file to a temporary file and returns a tuple(filename, headers)
urlopen
returns aRequest
object whoseread
method returns a bytestring containing the file contents
这篇关于AttributeError:“模块"对象没有属性"urlretrieve"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文