Video 24 not working

0 Neil Macintyre · July 24, 2015
I get  <bound method HTTPResponse.read of <http.client.HTTPResponse object at 0x7fdd301e97f0>> as a response when I run

from urllib import request

goog_url = 'http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT&f=snbaopl1'
sp500_url = 'http://real-chart.finance.yahoo.com/table.csv?s=%5EGSPC&d=6&e=23&f=2015&g=d&a=0&b=3&c=1950&ignore=.csv'


def download_stock_data(csv_url):
response = request.urlopen(csv_url)
csv = response.read
csv_str = str(csv)
print(csv_str)
lines = csv_str.split("\\n")
url_dest = r'sp500.csv'
fx = open(url_dest, "w")
for line in lines:
fx.write(line + "\n")
fx.close()

print("finished")


download_stock_data(goog_url)


Is this caused by a change in Yahoos apis or is there an error in my code 

Post a Reply

Replies

Oldest  Newest  Rating
0 Lotfi Ace · July 28, 2015
You forgot the brackets after response.read

change it to  csv = response.read()

and it will work fine,
0 Neil Macintyre · August 14, 2015
Thanks, that's all that need to be done
  • 1

Python

107,334 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator