python - Getting an empty jpg file, when try to Download an image -


i have been trying download image website (no username , password required) every time getting empty file. have used conventional urllib .retrieve , requests methodologies getting same result. 1 thing more if try open same image manually copy pasting url after 15-20 min image not open. assuming sort of session handling required in case . below code returns me empty image.

import os import urllib  def savepic(url):     uri="c:\python27\scripts\photosurl2.jpg"      if url!="":         urllib.urlretrieve(url, uri)  savepic("http://www-nass.nhtsa.dot.gov/nass/cds/getbinary.aspx?imageview&imageid=491410290&desc=lookback+from+final+rest&title=scene+photos+-+image1&version=1&extend=jpg") 

any appreciated.

when try implement http code in python not forget validate can use curl or wget perform these http requests. save lot of time trying debug problem not in code.

the have verbose modes give hints regarding missing.

also, senior python developers using requests library instead of urllib ones.

ps. requests library easier use urllib.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -