pkout / yahoo_finance_api2

API to interact with Yahoo Finance
MIT License
39 stars 13 forks source link

bump into simplejson.errors.JSONDecodeError #9

Closed ameobafiesta closed 3 years ago

ameobafiesta commented 3 years ago

Thank you for writing such an easy to use library! I use it almost everyday, it always works like a charm, yet the below errors was what I got today

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/init.py", line 1883, in call return self.func(*args) File "/Users/bigsur/PycharmProjects/futu/venv/yahoo finance.py", line 1594, in run_yahoo_finance data = get_day(5) File "/Users/bigsur/PycharmProjects/futu/venv/yahoo finance.py", line 212, in get_day symbol_data = my_share.get_historical(share.PERIOD_TYPE_DAY, File "/Users/bigsur/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/yahoo_finance_api2/share.py", line 26, in get_historical data = self._download_symbol_data(period_type, period, File "/Users/bigsur/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/yahoo_finance_api2/share.py", line 94, in _download_symbol_data resp_json = requests.get(url).json() File "/Users/bigsur/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/requests/models.py", line 900, in json return complexjson.loads(self.text, **kwargs) File "/Users/bigsur/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/simplejson/init.py", line 525, in loads return _default_decoder.decode(s) File "/Users/bigsur/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "/Users/bigsur/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

any clues?

chimesness commented 3 years ago

I had same problem. I didn't know why, but I found temporary solution. Copy share.py to your project, and change following sentence "from yahoo_finance_api2 import share" to "import share". It should come in useful until fixed original "yahoo_finance_api2" pip.

pkout commented 3 years ago

I just tried running the code in the example.py file and it worked without issues. Can you share more of your code?

chimesness commented 3 years ago

In my case, exmple.py is not working. I could get data using above temporary solution. But that data's timestamp is U.S. time. So this problem may happen when using program in other country, like Japan...

yasu0519 commented 3 years ago

The latest version installed by pip is "0.0.11", but it's older than this repository. Works with the latest code from this repository.

This is the code I made a pull request. -> https://github.com/pkout/yahoo_finance_api2/pull/8

yasu0519 commented 3 years ago

ver 0.0.11 is... Since "user-agent" is not added to the http request header, an http403 error occurs. The response of the http 403 error is not the correct json, so I get a JSONDecodeError.

Gen-TOD commented 3 years ago

Thank you for updating "share.py". It is working well !!

pkout commented 3 years ago

I just published version 0.12 to Pipy. Should be all good now.

ameobafiesta commented 3 years ago

Thank you so much, it's working now