Skip to content Skip to sidebar Skip to footer

Python Url Download

The code below returns none. How can I fix it? I'm using Python 2.6. import urllib URL = 'http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sl1t1v&e=.csv' symbols = ('

Solution 1:

You have to explicitly return the data from fetch_quote function. Something like this:

def fetch_quote(symbols):
    url = URL % '+'.join(symbols)
    fp = urllib.urlopen(url)
    try:
        data = fp.read()
    finally:
        fp.close()
    return data # <======== Return

In the absence of an explicit return statement Python returns None which is what you are seeing.

Solution 2:

Your method doesn't explicitly return anything, so it returnsNone

Post a Comment for "Python Url Download"