Open javiertrek opened 5 months ago
Hi,
Try printing out what the response from the requests.get()
call without
the json()
conversion is on line 95 in share.py
print(requests.get(url, headers=headers))
What is it returning? It probably isn't JSON.
On Mon, Jun 3, 2024 at 10:16 AM Fco. Javier Bermejo < @.***> wrote:
If you try Example.py or other file.py you get this message:
Traceback (most recent call last): File "C:\ProgramData\anaconda3\Lib\site-packages\requests\models.py", line 974, in json return complexjson.loads(self.text, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\json_init*_.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Jan\Documents\Python Scripts\ScanTrade.py", line 90, in symbol_data = my_share.get_historical(period_type, period_value, frecuency_type, frecuency_value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Jan\Documents\Python Scripts\share.py", line 26, in get_historical data = self._download_symbol_data(period_type, period, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Jan\Documents\Python Scripts\share.py", line 95, in _download_symbol_data resp_json = requests.get(url, headers=headers).json() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\site-packages\requests\models.py", line 978, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
any idea about it????
— Reply to this email directly, view it on GitHub https://github.com/pkout/yahoo_finance_api2/issues/11, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCVGL2EEAFNTKY7KQLKVT3ZFSQFDAVCNFSM6AAAAABIW5ONKWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGMZTCNRWGU3TGOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
I edited 95 line and changed this line: resp_json = requests.get(url, headers=headers).json() ---- this line break code.
by these other lines: resp_json = requests.get(url, headers=headers) print( requests.get(url, headers=headers) )
The printed out is:
<Response [429]>
is it clear for you???
I fixed it....
429 error from yahoo is for TOO MANY REQUESTS..... I don't know why buy something change in yahoo..... but it's easy to fix it. And I don't make too many requests.......
In share.py only change line: headers = {'User-Agent': ''}
by this other and it works: headers = {'User-Agent': 'your bot 0.1'}
They protect their service to some extent because there are many robots trying to scrape the data all the time. Glad you figured it out.
On Mon, Jun 3, 2024 at 11:44 AM FJB @.***> wrote:
I fixed it....
429 error from yahoo is for TOO MANY REQUESTS..... I don't know why buy something change in yahoo..... but it's easy to fix it. And I don't make too many requests.......
In share.py only change line: headers = {'User-Agent': ''}
by this other and it works: headers = {'User-Agent': 'your bot 0.1'}
— Reply to this email directly, view it on GitHub https://github.com/pkout/yahoo_finance_api2/issues/11#issuecomment-2145889215, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCVGL5CF6KSHFJ3A4N2KNDZFS2RZAVCNFSM6AAAAABIW5ONKWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBVHA4DSMRRGU . You are receiving this because you commented.Message ID: @.***>
If you try Example.py or other file.py you get this message:
Traceback (most recent call last): File "C:\ProgramData\anaconda3\Lib\site-packages\requests\models.py", line 974, in json return complexjson.loads(self.text, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\json__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Jan\Documents\Python Scripts\ScanTrade.py", line 90, in
symbol_data = my_share.get_historical(period_type, period_value, frecuency_type, frecuency_value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Jan\Documents\Python Scripts\share.py", line 26, in get_historical
data = self._download_symbol_data(period_type, period,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Jan\Documents\Python Scripts\share.py", line 95, in _download_symbol_data
resp_json = requests.get(url, headers=headers).json()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\anaconda3\Lib\site-packages\requests\models.py", line 978, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
any idea about it????