ystockquote icon indicating copy to clipboard operation
ystockquote copied to clipboard

urllib.error.HTTPError: HTTP Error 999: Request denied

Open sdglobe opened this issue 6 years ago • 7 comments

got error trying to run ystockquote.get_price('AAPL') or ystockquote.get_all('AAPL') What is the issue here?

sdglobe avatar Nov 02 '17 01:11 sdglobe

The same problem

HenryWan16 avatar Nov 02 '17 02:11 HenryWan16

Looks like Yahoo is shutting down this service. Error message is now: 403 Forbidden It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com

wawa12 avatar Nov 02 '17 22:11 wawa12

Both Yahoo! and Google have changed or shut down their APIs. Is there another source of data, such as the markets themselves or brokers (at least for their customers)? I see very little discussion of alternatives, but some, such as (scroll down a bit):

https://stackoverflow.com/questions/46080632/http-error-404-from-googlefinance-in-python-2-7/46081537#46081537

--jh--

joeharr4 avatar Nov 11 '17 01:11 joeharr4

Something like this seems to still work, I recently switched from ystockquote to it:

import json
import requests

symbol = 'ANET'
response = requests.get('https://finance.google.com/finance?output=json&q=' + symbol)
# The response is not valid JSON if you don't strip the leading "\n//"
text = response.text.lstrip()[2:]
quote = json.loads(text)

7AC avatar Nov 11 '17 03:11 7AC

+1 I'm seeing a 302 redirect to a dead end:

Traceback (most recent call last):
  File "stockticker-ledboard.py", line 52, in <module>
    allInfo = ystockquote.get_all(tickerSymbol)
  File "/usr/local/lib/python2.7/dist-packages/ystockquote.py", line 47, in get_all
    values = _request(symbol, ids).split(',')
  File "/usr/local/lib/python2.7/dist-packages/ystockquote.py", line 32, in _request
    resp = urlopen(req)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 469, in error
    result = self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 656, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 469, in error
    result = self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 656, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/usr/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1227, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>

swoodford avatar Feb 12 '18 17:02 swoodford

I found someone on the web did produce a working google query:
https://www.google.com/finance/getprices?q=MKSI&x=NASDAQ&i=60&p=2d&f=d,c,h,l,o,v

URL output to browser looks like this:

EXCHANGE%3DNASDAQ MARKET_OPEN_MINUTE=570 MARKET_CLOSE_MINUTE=960 INTERVAL=60 COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME DATA= TIMEZONE_OFFSET=-240 a1524231000,105.25,105.25,105.2,105.2,25558 1,105.225,105.275,104.65,105.25,20164 2,105.4,105.5,104.75,104.75,4997 .... ....

I’m no python coder, but was curious to see where such development is at this point. Happy to hear if this is picked up again.

Snortfire avatar Apr 23 '18 23:04 Snortfire

Something like this seems to still work, I recently switched from ystockquote to it:

import json
import requests

symbol = 'ANET'
response = requests.get('https://finance.google.com/finance?output=json&q=' + symbol)
# The response is not valid JSON if you don't strip the leading "\n//"
text = response.text.lstrip()[2:]
quote = json.loads(text)

It's returning the google finance webpage

Samar-080301 avatar Dec 31 '20 11:12 Samar-080301