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

JSONDecodeError for nse_eq('PVR') #25

Closed
reachbharathan opened this issue May 3, 2023 · 7 comments
Closed

JSONDecodeError for nse_eq('PVR') #25

reachbharathan opened this issue May 3, 2023 · 7 comments

Comments

@reachbharathan
Copy link

reachbharathan commented May 3, 2023

Hi Team,
I have installed the library via pip3

while executing the below code , I am getting the below error mentioned

from nsepython import *

print(indices)
# print(nse_optionchain_scrapper('PVR'))
print(nse_eq('PVR'))

Error Code
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Complete Error Code

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/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 "/Users/thoughtworks/projects/coursera/pythonPract/stock-details.py", line 5, in <module>
    print(nse_eq('PVR'))
          ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nsepython/rahu.py", line 289, in nse_eq
    payload = nsefetch('https://www.nseindia.com/api/quote-equity?symbol='+symbol)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nsepython/rahu.py", line 18, in nsefetch
    output = requests.get(payload,headers=headers).json()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

System Configuration:
Mac
Python 3.11.2
pip 23.1.2

@TheRealXenoZ
Copy link

facing a similar situation using equity_history() method.

JSONDecodeError                           Traceback (most recent call last)
File [x:\Projects\PopProj\venv\lib\site-packages\requests\models.py:971](file:///X:/Projects/PopProj/venv/lib/site-packages/requests/models.py:971), in Response.json(self, **kwargs)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File [~\AppData\Local\Programs\Python\Python310\lib\json\__init__.py:346](https://file+.vscode-resource.vscode-cdn.net/x%3A/Projects/RSB/~/AppData/Local/Programs/Python/Python310/lib/json/__init__.py:346), in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File [~\AppData\Local\Programs\Python\Python310\lib\json\decoder.py:337](https://file+.vscode-resource.vscode-cdn.net/x%3A/Projects/RSB/~/AppData/Local/Programs/Python/Python310/lib/json/decoder.py:337), in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File [~\AppData\Local\Programs\Python\Python310\lib\json\decoder.py:355](https://file+.vscode-resource.vscode-cdn.net/x%3A/Projects/RSB/~/AppData/Local/Programs/Python/Python310/lib/json/decoder.py:355), in JSONDecoder.raw_decode(self, s, idx)
...
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

@reachbharathan
Copy link
Author

@praful-vats can you confirm if nsepython is still working?

@reachbharathan
Copy link
Author

@TheRealXenoZ are you receiving this error only for specific method, I am receiving the error for all the methods.
can you confirm other methods are working as expected.

@alloc7260
Copy link

alloc7260 commented May 5, 2023

@reachbharathan @praful-vats some function of nsepython depends on nsepy so if you are using those they will not work

@anil8593
Copy link

Changing the URL to the following fixed my problem:

"https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES IN F%26O"

P.S. The url still sometimes fails, add retries and try except in your code should help

@alloc7260
Copy link

There is lot's of apis in nse that they use internally.
Each api has it's own use that can be used while in different scenarios.

@aeron7
Copy link
Owner

aeron7 commented May 13, 2023

Please use https://forum.unofficed.com/c/programming/nse-python-api/21 for discussion. Every single problem needs attention and I cannot attend everything in unorganized manner.

@aeron7 aeron7 closed this as completed May 13, 2023
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

5 participants