Reputation: 59
I got a list named href_w with a bunch of mp3 links to download, but when I execute this piece of code, it gives me an error:
# Download file
print(color.BLUE + "\n[*] Downloading requested mp3(s) ..." + color.END)
for link in href_w:
url = "http://www.mp3c.cc"+link.replace('track','files')
print("[*] GET "+url)
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
response = urlopen(req)
html = response.read()
The error log looks like this:
[*] Downloading requested mp3(s) ...
[*] GET http://www.mp3c.cc/files/88144527_288384031/
Traceback (most recent call last):
File "mp3spyder.py", line 99, in <module>
response = urlopen(req)
File "/usr/lib/python3.4/urllib/request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.4/urllib/request.py", line 461, in open
response = meth(req, response)
File "/usr/lib/python3.4/urllib/request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.4/urllib/request.py", line 493, in error
result = self._call_chain(*args)
File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/lib/python3.4/urllib/request.py", line 676, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/lib/python3.4/urllib/request.py", line 461, in open
response = meth(req, response)
File "/usr/lib/python3.4/urllib/request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.4/urllib/request.py", line 499, in error
return self._call_chain(*args)
File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/lib/python3.4/urllib/request.py", line 579, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 502: Bad Gateway
What can I do to do it right?
Upvotes: 1
Views: 831
Reputation: 3
I used this script. It takes url of file, reads it and saves it to file. Here is an example with downloaded mp3.
import urllib
url = 'http://www.drowtales.com/download/Path%20to%20Power.mp3'
data = urllib.request.urlopen(url)
f = open('Path to Power.mp3','wb')
f.write(data.read())
f.close()
Upvotes: 0
Reputation: 170846
If you get a 502 response from the web server it usually means that their backend is down. You would probably get the same response if you would use curl or wget.
Anyway, you should always try curl or wget in order to debug such problems.
Upvotes: 1