Issue
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'
The line that is causing this problem is
raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")
Solution
As you're using Python 3, there is no urllib
module anymore. It has been split into several modules.
This would be equivalent to urlretrieve
:
import urllib.request
data = urllib.request.urlretrieve("http://...")
urlretrieve
behaves exactly the same way as it did in Python 2.x, so it'll work just fine.
Basically:
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
Answered By - dom0
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.