0

Python code:

    import urllib2
    import requests
    info_hash = '00001BD2C9F364C7DCB759DEC6BE02F913C96F72'
    url = 'http://torrage.com/torrent/%s.torrent' % info_hash
    print url
    data = urllib2.urlopen(url).read() # this data is err
    # data = requests.get(url).content # this data is ok
    f = open('%s.torrent' % info_hash, 'wb')
    f.write(data)
    f.close()

I can't get right torrent content by the code, but I can get right torrent by the url in browser.

oz123
  • 27,559
  • 27
  • 125
  • 187
40robber
  • 29
  • 5
  • 4
    Why not just use `requests` if it works? – Cfreak Nov 18 '13 at 16:28
  • 3
    well, at least it has an eight on [imdb](http://www.imdb.com/title/tt1731881/?ref_=fn_al_tt_2), so we are not doing this for nothing. – RickyA Nov 18 '13 at 16:32
  • @Cfreak yes, it works, but i want to konw:why urllib2 doesn't work(i use)? requests is another form of urllib2. thx – 40robber Nov 18 '13 at 16:34
  • Without the error there's really not info for us to figure out. Could be a URL encoding problem which `requests` solves for you. – Cfreak Nov 18 '13 at 16:40
  • Or a redirect.. Can we have the exception, error codes, status codes and raw html? – RickyA Nov 18 '13 at 16:41
  • try unzipping the response body: http://stackoverflow.com/questions/3947120/does-python-urllib2-will-automaticly-uncompress-gzip-data-from-fetch-webpage – Jan Zeiseweis Nov 18 '13 at 16:43

0 Answers0