python - Using urllib2 to fetch internet resources, get http 402 error -
i tried use urllib2 fetch zip file subtitle website.
the example website http://sub.makedie.me , tried download file http://sub.makedie.me/download/601943/game%20of%20thrones%20-%2005x08%20-%20hardhome.killers.english.hi.c.orig.addic7ed.com.zip
i tested in script , print url. url fine. copied , pasted in web browser , download successfully.
at first, script looked this:
    try:         f = urllib2.urlopen(example_url)         f.read()         something...     except urlerror, e:         print e.code   but got 403 error code. after searching, tried change header {'user-agent': 'mozilla/5.0'}. code changed to:
    try:         req = urllib2.request(example_url,headers={'user-agent': 'mozilla/5.0'})         f = urllib2.urlopen(req)         something...     except urlerror, e:         print e.code   then got 402 error. wondering because of website setting or because error in code?
i try with:
urllib.urlretrieve(url, outname)   as trying download file rather open it.
Comments
Post a Comment