python - Urllib2 <urlopen error [Errno -5] No address associated with hostname> -


i have python program uses several apis, including 2 yahoo!. 1 having trouble with, however. gives me error <urlopen error [errno -5] no address associated hostname> here outputs various terminal commands try data "http://download.finance.yahoo.com/d/quotes.csv?s=goog&f=nsl1l2op&e=.csv":

my code:

def stocks():     lcd.clear()     lcd.message('raspi stocks\nusing yahoo!')     time.sleep(2)     val = 1     in stockslst: #           host = urllib2.socket.gethostbyname('finance.yahoo.com')             req = urllib2.request('http://download.finance.yahoo.com/d/quotes.csv?s=' + + '&f=nsl1l2op&e=.csv$             req.add_header('host:', 'finance.yahoo.com')             mdata = urllib2.urlopen(req)             csvdata = [row row in csv.reader(mdata)]             sname = csvdata[0][0]             last1 = float(csvdata[0][2])             last2 = float(csvdata[0][3])             if last1 > last2:                     r = 0             if last1 < last2:                     r = 1             if last1 == last2:                     r = 126             lcd.clear()             lcd.message(sname + '\n' + chr(r) + str(last1))             time.sleep(2) 

my program:

pi@raspberrypi ~ $ sudo python lcddisplayrpi.py traceback (most recent call last): file "lcddisplayrpi.py", line 132, in <module> stocks() file "lcddisplayrpi.py", line 113, in stocks mdata = urllib2.urlopen(req) file "/usr/lib/python2.7/urllib2.py", line 127, in urlopen return _opener.open(url, data, timeout) file "/usr/lib/python2.7/urllib2.py", line 401, in open response = self._open(req, data) file "/usr/lib/python2.7/urllib2.py", line 419, in _open '_open', req) file "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain result = func(*args) file "/usr/lib/python2.7/urllib2.py", line 1211, in http_open return self.do_open(httplib.httpconnection, req) file "/usr/lib/python2.7/urllib2.py", line 1181, in do_open raise urlerror(err) urllib2.urlerror: <urlopen error [errno -5] no address associated hostname> 

curl problematic address:

curl "http://finance.yahoo.com/d/quotes.csv?s=goog&f=nsl1l2op&e=.csv" <head><title>redirect</title></head> <body bgcolor="white" fgcolor="black"> <font face="helvetica,arial"><b>  "<em>http://download.finance.yahoo.com/d/quotes.csv?s=goog&f=nsl1l2op&e=.csv</em>".<p></b></font>  <!-- default "redirect" response (301) --> </body> 

wget problematic address:

 wget "http://finance.yahoo.com/d/quotes.csv?s=goog&f=nsl1l2op&e=.csv" --2013-10-06 09:01:30--  http://finance.yahoo.com/d/quotes.csv?s=goog&f=nsl1l2op&e=.csv resolving finance.yahoo.com (finance.yahoo.com)... failed: no address associated hostname. wget: unable resolve host address `finance.yahoo.com' 

i can csv data in web browser on same computer. hinted in curl command, tried changing download.finance.yahoo.com, no luck python program. tried curl again:

curl "http://download.finance.yahoo.com/d/quotes.csv?s=goog&f=nsl1l2op&e=.csv" "google inc.","goog",872.35,-,876.00,876.09 

this data want. don't know wrong python program.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

html - Repeat image to extend header to fill screen -

javascript - Backbone.js getting target attribute -