Ask coding questions

← Back to all posts
The yahoo finance library seems to not be working?
JacobMacLeod

I am trying to use the yahoo finance libary to get prices of stocks. I am using this webpage 'https://pypi.org/project/yahoo-finance/' and am trying to use the 'Get shares data' part under 'Get Usage Data' code. I pasted the lines of code in that were in the example, and got an error. After playing around with the code for a bit, I got this error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/usr/local/lib/python3.7/http/client.py", line 1244, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 966, insend
self.connect()
File "/usr/local/lib/python3.7/http/client.py", line 1406, in connect
super().connect()
File "/usr/local/lib/python3.7/http/client.py", line 938, inconnect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/local/lib/python3.7/socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/local/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 2, in <module>
yahoo = Share('YHOO')
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 178, in init
self.refresh()
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 142, in refresh
self.data_set = self._fetch()
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 181, in _fetch
data = super(Share, self)._fetch()
Traceback (most recent call last): File "/usr/local/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/usr/local/lib/python3.7/http/client.py", line 1244, in request self._send_request(method, url, body, headers, encode_chunk
ed)
File "/usr/local/lib/python3.7/http/client.py", line 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunk
ed) File "/usr/local/lib/python3.7/http/client.py", line 1026, in
_send_output
self.send(msg) File "/usr/local/lib/python3.7/http/client.py", line 966, in
send
self.connect() File "/usr/local/lib/python3.7/http/client.py", line 1406, in
connect
super().connect() File "/usr/local/lib/python3.7/http/client.py", line 938, in
connect
(self.host,self.port), self.timeout, self.source_address) File "/usr/local/lib/python3.7/socket.py", line 707, in creat
e_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "/usr/local/lib/python3.7/socket.py", line 748, in getad
drinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 2, in <module>
yahoo = Share('YHOO')
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 178, in init
self.refresh()
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 142, in refresh
self.data_set = self._fetch()
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 181, in _fetch
data = super(Share, self)._fetch()
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 134, in _fetch
data = self._request(query)
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/init.py", line 118, in _request
response = yql.YQLQuery().execute(query)
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/yahoo_finance/yql.py", line 61, in execute
'env': DATATABLES_URL
File "/usr/local/lib/python3.7/urllib/request.py", line 222,in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.7/urllib/request.py", line 525,in open
response = self._open(req, data)
File "/usr/local/lib/python3.7/urllib/request.py", line 543,in _open
'_open', req)
File "/usr/local/lib/python3.7/urllib/request.py", line 503,in _call_chain
result = func(*args)
File "/usr/local/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/usr/local/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -5] No address associated with hostname>
Does it look like it is an error with the code yahoo finance is build on or something? It doesn't look like it is to do with my code

Voters
YuvMalik
JacobMacLeod
Comments
hotnewtop
Felecia-UlphiUl

Lol, dude, this is something very difficult for me, I first want to figure out what companies are in the finance field and start figuring it out. Since now there are some savings that I want to invest in order to make a profit, but I cannot yet understand how and where it is better to invest these savings

YuvMalik

Same problem