Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: paris_test
Views: 399
Kernel: Python 3 (Anaconda)
from pandas_datareader import data as pdr # download dataframe data = pdr.get_data_yahoo("SPY", start="2017-01-01", end="2017-04-30") type(data) data.head()
--------------------------------------------------------------------------- TimeoutError Traceback (most recent call last) /ext/anaconda3/lib/python3.5/site-packages/urllib3/connection.py in _new_conn(self) 140 conn = connection.create_connection( --> 141 (self.host, self.port), self.timeout, **extra_kw) 142 /ext/anaconda3/lib/python3.5/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options) 82 if err is not None: ---> 83 raise err 84 /ext/anaconda3/lib/python3.5/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options) 72 sock.bind(source_address) ---> 73 sock.connect(sa) 74 return sock TimeoutError: [Errno 110] Connection timed out During handling of the above exception, another exception occurred: NewConnectionError Traceback (most recent call last) /ext/anaconda3/lib/python3.5/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 599 body=body, headers=headers, --> 600 chunked=chunked) 601 /ext/anaconda3/lib/python3.5/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw) 344 try: --> 345 self._validate_conn(conn) 346 except (SocketTimeout, BaseSSLError) as e: /ext/anaconda3/lib/python3.5/site-packages/urllib3/connectionpool.py in _validate_conn(self, conn) 843 if not getattr(conn, 'sock', None): # AppEngine might not have `.sock` --> 844 conn.connect() 845 /ext/anaconda3/lib/python3.5/site-packages/urllib3/connection.py in connect(self) 283 # Add certificate verification --> 284 conn = self._new_conn() 285 /ext/anaconda3/lib/python3.5/site-packages/urllib3/connection.py in _new_conn(self) 149 raise NewConnectionError( --> 150 self, "Failed to establish a new connection: %s" % e) 151 NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f613d3cd1d0>: Failed to establish a new connection: [Errno 110] Connection timed out During handling of the above exception, another exception occurred: MaxRetryError Traceback (most recent call last) /ext/anaconda3/lib/python3.5/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 439 retries=self.max_retries, --> 440 timeout=timeout 441 ) /ext/anaconda3/lib/python3.5/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 648 retries = retries.increment(method, url, error=e, _pool=self, --> 649 _stacktrace=sys.exc_info()[2]) 650 retries.sleep() /ext/anaconda3/lib/python3.5/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace) 387 if new_retry.is_exhausted(): --> 388 raise MaxRetryError(_pool, url, error or ResponseError(cause)) 389 MaxRetryError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/SPY/history (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f613d3cd1d0>: Failed to establish a new connection: [Errno 110] Connection timed out',)) During handling of the above exception, another exception occurred: ConnectionError Traceback (most recent call last) <ipython-input-1-a21ad57fbdea> in <module>() 3 4 # download dataframe ----> 5 data = pdr.get_data_yahoo("SPY", start="2017-01-01", end="2017-04-30") 6 type(data) 7 /ext/anaconda3/lib/python3.5/site-packages/pandas_datareader/data.py in get_data_yahoo(*args, **kwargs) 38 39 def get_data_yahoo(*args, **kwargs): ---> 40 return YahooDailyReader(*args, **kwargs).read() 41 42 /ext/anaconda3/lib/python3.5/site-packages/pandas_datareader/yahoo/daily.py in __init__(self, symbols, start, end, retry_count, pause, session, adjust_price, ret_index, chunksize, interval) 80 81 self.interval = '1' + self.interval ---> 82 self.crumb = self._get_crumb(retry_count) 83 84 @property /ext/anaconda3/lib/python3.5/site-packages/pandas_datareader/yahoo/daily.py in _get_crumb(self, retries) 156 tu = "https://finance.yahoo.com/quote/{}/history".format(self.symbols) 157 response = self._get_response(tu, --> 158 params=self.params, headers=self.headers) 159 out = str(self._sanitize_response(response)) 160 # Matches: {"crumb":"AlphaNumeric"} /ext/anaconda3/lib/python3.5/site-packages/pandas_datareader/base.py in _get_response(self, url, params, headers) 124 response = self.session.get(url, 125 params=params, --> 126 headers=headers) 127 if response.status_code == requests.codes.ok: 128 return response /ext/anaconda3/lib/python3.5/site-packages/requests/sessions.py in get(self, url, **kwargs) 519 520 kwargs.setdefault('allow_redirects', True) --> 521 return self.request('GET', url, **kwargs) 522 523 def options(self, url, **kwargs): /ext/anaconda3/lib/python3.5/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 506 } 507 send_kwargs.update(settings) --> 508 resp = self.send(prep, **send_kwargs) 509 510 return resp /ext/anaconda3/lib/python3.5/site-packages/requests/sessions.py in send(self, request, **kwargs) 616 617 # Send the request --> 618 r = adapter.send(request, **kwargs) 619 620 # Total elapsed time of the request (approximately) /ext/anaconda3/lib/python3.5/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 506 raise SSLError(e, request=request) 507 --> 508 raise ConnectionError(e, request=request) 509 510 except ClosedPoolError as e: ConnectionError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/SPY/history (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f613d3cd1d0>: Failed to establish a new connection: [Errno 110] Connection timed out',))
import pandas as pd from pandas_datareader import data, wb # Package and modules for importing data; this code may change depending on pandas version import datetime # We will look at stock prices over the past year, starting at January 1, 2016 start = datetime.datetime(2016,1,1) end = datetime.date.today() # Let's get Apple stock data; Apple's ticker symbol is AAPL # First argument is the series we want, second is the source ("yahoo" for Yahoo! Finance), third is the start date, fourth is the end date apple = wb.datareader("AAPL", 'yahoo',start, end) type(apple) apple.head()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-2-7cd99f54bd70> in <module>() 9 # Let's get Apple stock data; Apple's ticker symbol is AAPL 10 # First argument is the series we want, second is the source ("yahoo" for Yahoo! Finance), third is the start date, fourth is the end date ---> 11 apple = wb.datareader("AAPL", 'yahoo',start, end) 12 13 type(apple) AttributeError: module 'pandas_datareader.wb' has no attribute 'datareader'