Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gaierror #26

Open
swyuhui opened this issue May 7, 2019 · 0 comments
Open

gaierror #26

swyuhui opened this issue May 7, 2019 · 0 comments

Comments

@swyuhui
Copy link

swyuhui commented May 7, 2019

I have been using fredapi to download data from FRED API without problem. But I've been trying to run the same codes that I had before in these two days and I keep getting something called "gaierror".

Here is the codes that I ran (I just masked the API key):
from fredapi import Fred
fred = Fred(api_key='xxxxxxxxxxxxxxxxxxxxxxxxx')
import pandas as pd
data = fred.get_series('SP500')

and I got the following error. Can anyone help me to understand what error it is and how to solve it? Thanks a lot.

gaierror Traceback (most recent call last)
/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1253 try:
-> 1254 h.request(req.get_method(), req.selector, req.data, headers)
1255 except OSError as err: # timeout error

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/http/client.py in request(self, method, url, body, headers)
1106 """Send a complete request to the server."""
-> 1107 self._send_request(method, url, body, headers)
1108

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/http/client.py in _send_request(self, method, url, body, headers)
1151 body = _encode(body, 'body')
-> 1152 self.endheaders(body)
1153

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/http/client.py in endheaders(self, message_body)
1102 raise CannotSendHeader()
-> 1103 self._send_output(message_body)
1104

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/http/client.py in _send_output(self, message_body)
933
--> 934 self.send(msg)
935 if message_body is not None:

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/http/client.py in send(self, data)
876 if self.auto_open:
--> 877 self.connect()
878 else:

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/http/client.py in connect(self)
1252
-> 1253 super().connect()
1254

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/http/client.py in connect(self)
848 self.sock = self._create_connection(
--> 849 (self.host,self.port), self.timeout, self.source_address)
850 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/socket.py in create_connection(address, timeout, source_address)
693 err = None
--> 694 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
695 af, socktype, proto, canonname, sa = res

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/socket.py in getaddrinfo(host, port, family, type, proto, flags)
732 addrlist = []
--> 733 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
734 af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

URLError Traceback (most recent call last)
in ()
----> 1 data = fred.get_series('SP500')

/home/nbkz19v/.local/lib/python3.5/site-packages/fredapi/fred.py in get_series(self, series_id, observation_start, observation_end, **kwargs)
129 if kwargs.keys():
130 url += '&' + urlencode(kwargs)
--> 131 root = self.__fetch_data(url)
132 if root is None:
133 raise ValueError('No data exists for series id: ' + series_id)

/home/nbkz19v/.local/lib/python3.5/site-packages/fredapi/fred.py in __fetch_data(self, url)
62 url += '&api_key=' + self.api_key
63 try:
---> 64 response = urlopen(url)
65 root = ET.fromstring(response.read())
66 except HTTPError as exc:

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
161 else:
162 opener = _opener
--> 163 return opener.open(url, data, timeout)
164
165 def install_opener(opener):

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/urllib/request.py in open(self, fullurl, data, timeout)
464 req = meth(req)
465
--> 466 response = self._open(req, data)
467
468 # post-process response

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/urllib/request.py in _open(self, req, data)
482 protocol = req.type
483 result = self._call_chain(self.handle_open, protocol, protocol +
--> 484 '_open', req)
485 if result:
486 return result

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
442 for handler in handlers:
443 func = getattr(handler, meth_name)
--> 444 result = func(*args)
445 if result is not None:
446 return result

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/urllib/request.py in https_open(self, req)
1295 def https_open(self, req):
1296 return self.do_open(http.client.HTTPSConnection, req,
-> 1297 context=self._context, check_hostname=self.check_hostname)
1298
1299 https_request = AbstractHTTPHandler.do_request

/storage/EIX_LAB_NH_1/install/anaconda3/lib/python3.5/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1254 h.request(req.get_method(), req.selector, req.data, headers)
1255 except OSError as err: # timeout error
-> 1256 raise URLError(err)
1257 r = h.getresponse()
1258 except:

URLError: <urlopen error [Errno -2] Name or service not known>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant