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

get_quote() returns HTTP error 301 #145

Open
kgsatish opened this issue Aug 26, 2023 · 3 comments
Open

get_quote() returns HTTP error 301 #145

kgsatish opened this issue Aug 26, 2023 · 3 comments

Comments

@kgsatish
Copy link

This exmaple is taken from nsetools documentation. But it did not work:

from nsetools import Nse
nse = Nse()
quote = nse.get_quote('infy')
from pprint import pprint
pprint(quote)

This is the error:

Traceback (most recent call last):
  File "g:\My Drive\development\aitrading\nse.py", line 4, in <module>
    quote = nse.get_quote('infy')
            ^^^^^^^^^^^^^^^^^^^^^
  File "G:\My Drive\development\aitrading\.venv\Lib\site-packages\nsetools\nse.py", line 152, in get_quote
    if self.is_valid_code(code):
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "G:\My Drive\development\aitrading\.venv\Lib\site-packages\nsetools\nse.py", line 138, in is_valid_code
    stock_codes = self.get_stock_codes()
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "G:\My Drive\development\aitrading\.venv\Lib\site-packages\nsetools\nse.py", line 117, in get_stock_codes
    res = self.opener.open(req)
          ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 557, in error
    result = self._call_chain(*args)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 557, in error
    result = self._call_chain(*args)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 557, in error
    result = self._call_chain(*args)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 557, in error
    result = self._call_chain(*args)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 557, in error
    result = self._call_chain(*args)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 557, in error
    result = self._call_chain(*args)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Python311\Lib\urllib\request.py", line 738, in http_error_302
    raise HTTPError(req.full_url, code,
urllib.error.HTTPError: HTTP Error 301: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Moved Permanently
@nandi691
Copy link

nandi691 commented Aug 27, 2023

I am working on Linux OS.
I uninstalled the package by pip uninstall nsetools
I cloned the latest nsetools in ~/python_packages

import sys
sys.path.insert(0,"~/python_packages")
from nsetools import Nse

I am able to get nse.get_quote, but I think NSE has limited the parameters.

Other issues still exists

@kgsatish
Copy link
Author

Cool! This worked! I tried on windows as well and it works.

How is git clone different from pip install?

@saurabhv749
Copy link

Hi sir, if you go to the pip page of the library:
nsetools- PIP you will see that it's latest version is 1.0.11 which was published on 10 feb 2020.

however the main github repo was updated 3months ago. so the PIP library isn't up to date.
I hope this answers your query.

the dev should add a workflow to automatically publish the latest version on pip when he make changes in the github codebase.

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

3 participants