I am trying to get the last closed price of a stock. And the nsefetch()
gets a 401 error response. And when we try to get json from it we get a requests.exceptions.JSONDecodeError
from nsepython import *
symbol = 'SWSOLAR'
print(nse_eq(symbol)['priceInfo']['close'])
{'_content': b'<!DOCTYPE html>\r\n<html lang="en">\r\n<head>\r\n <meta chars'
b'et="UTF-8">\r\n <title>Oops</title>\r\n</head>\r\n<body style'
b'="background-color: #e8e8e8;">\r\n <div style="font-size: 14p'
b'x; padding: 50px 0; text-align: center;">\r\n <h1>\r\n N'
b'o authorization token was found\r\n </h1>\r\n <h2>\r\n '
b' 401\r\n </h2>\r\n <pre style="text-align: left; font-s'
b'ize: 11px;">UnauthorizedError: No authorization token was fo'
b'und\n at middleware (/www/nse-website-node-v2/files/node_m'
b'odules/express-jwt/lib/index.js:79:21)\n at Layer.handle ['
b'as handle_request] (/www/nse-website-node-v2/files/node_modules/'
b'express/lib/router/layer.js:95:5)\n at next (/www/nse-webs'
b'ite-node-v2/files/node_modules/express/lib/router/route.js:137:1'
b'3)\n at attachCors (/www/nse-website-node-v2/files/server/'
b'middleware.js:188:3)\n at Layer.handle [as handle_request]'
b' (/www/nse-website-node-v2/files/node_modules/express/lib/router'
b'/layer.js:95:5)\n at next (/www/nse-website-node-v2/files/'
b'node_modules/express/lib/router/route.js:137:13)\n at Rout'
b'e.dispatch (/www/nse-website-node-v2/files/node_modules/express/'
b'lib/router/route.js:112:3)\n at Layer.handle [as handle_re'
b'quest] (/www/nse-website-node-v2/files/node_modules/express/lib/'
b'router/layer.js:95:5)\n at /www/nse-website-node-v2/files/'
b'node_modules/express/lib/router/index.js:281:22\n at Funct'
b'ion.process_params (/www/nse-website-node-v2/files/node_modules/'
b'express/lib/router/index.js:335:12)\n at next (/www/nse-we'
b'bsite-node-v2/files/node_modules/express/lib/router/index.js:275'
b':10)\n at next (/www/nse-website-node-v2/files/node_module'
b's/express/lib/router/route.js:127:14)\n at /www/nse-websit'
b'e-node-v2/files/server/routes.js:388:11</pre>\r\n </div>\r\n</b'
b'ody>\r\n</html>\r\n',
'_content_consumed': True,
'_next': None,
'connection': <requests.adapters.HTTPAdapter object at 0x151135cc0>,
'cookies': <RequestsCookieJar[Cookie(version=0, name='AKA_A2', value='A', port=None, port_specified=False, domain='.nseindia.com', domain_specified=True, domain_initial_dot=False, path='/', path_specified=True, secure=True, expires=1694352722, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False), Cookie(version=0, name='ak_bmsc', value='3FF27A5BD0D6CA89B241FE09D6BE37DD~000000000000000000000000000000~YAAQKkw5F3zBT3qKAQAAktwTfxVprxRxAcgBFTxytM1PfqlASuI9TI8joQ2Ye9qvEBer7lG6V75Y+iSYBuOnUAqBvmWyY0hnqnYcK7sgA9zVYAOHWG8/PCGTeqY6hGbYGkm9tELEjEU+PrLsdw8FePPXkRh1mDEqLOLegucczlNt1WBNI6lak4II4Ygd25ZzH40AabtyJpjwMcvYUfLHeYXPJHrnPlseOWqFRRy2wMQPBlEcGo/vU24kqu4lxCThxjcOFccUGIgx3pok3O1VXIwzbc3NDnRRzNdIrKJrov1u2HtH+e9rQbwx6zs6HwmknR9VFkosHJiG31AXheHIwupmiXSvEomrOsDLcSNbp5VG5aMh0WPvh7okBQKzkj60fw==', port=None, port_specified=False, domain='.nseindia.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=False, expires=1694356322, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)]>,
'elapsed': datetime.timedelta(microseconds=354280),
'encoding': 'utf-8',
'headers': {'Server': 'Apache', 'X-DNS-Prefetch-Control': 'off', 'X-Frame-Options': 'SAMEORIGIN', 'X-Download-Options': 'noopen', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Content-Security-Policy': "font-src *; default-src 'self' *; img-src * data: https://www.google.co.in https://www.google-analytics.com www.google-analytics.com https://nse-widget.interface.ai; style-src * 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.youtube.com *.gstatic.com https://www.google.com/ *.cloudflare.com *.googletagmanager.com *.highcharts.com *.go-mpulse.net https://stats.g.doubleclick.net/ https://www.google.com/ *.doubleclick.net https://nse-uat-widget.interface.ai/widget-loader.js www.google-analytics.com *.g.doubleclick.net/ https://analytics.google.com/ https://nse-widget.interface.ai", 'Access-Control-Allow-Origin': 'beta.nseindia.com, nseindia.com', 'Access-Control-Allow-Methods': 'GET,POST', 'Access-Control-Allow-Headers': 'Content-Type', 'Content-Type': 'text/html; charset=utf-8', 'Content-Encoding': 'gzip', 'Date': 'Sun, 10 Sep 2023 12:32:02 GMT', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive, Transfer-Encoding', 'Vary': 'Accept-Encoding', 'Set-Cookie': 'AKA_A2=A; expires=Sun, 10-Sep-2023 13:32:02 GMT; path=/; domain=nseindia.com; secure; HttpOnly, ak_bmsc=3FF27A5BD0D6CA89B241FE09D6BE37DD~000000000000000000000000000000~YAAQKkw5F3zBT3qKAQAAktwTfxVprxRxAcgBFTxytM1PfqlASuI9TI8joQ2Ye9qvEBer7lG6V75Y+iSYBuOnUAqBvmWyY0hnqnYcK7sgA9zVYAOHWG8/PCGTeqY6hGbYGkm9tELEjEU+PrLsdw8FePPXkRh1mDEqLOLegucczlNt1WBNI6lak4II4Ygd25ZzH40AabtyJpjwMcvYUfLHeYXPJHrnPlseOWqFRRy2wMQPBlEcGo/vU24kqu4lxCThxjcOFccUGIgx3pok3O1VXIwzbc3NDnRRzNdIrKJrov1u2HtH+e9rQbwx6zs6HwmknR9VFkosHJiG31AXheHIwupmiXSvEomrOsDLcSNbp5VG5aMh0WPvh7okBQKzkj60fw==; Domain=.nseindia.com; Path=/; Expires=Sun, 10 Sep 2023 14:32:02 GMT; Max-Age=7200; HttpOnly', 'Server-Timing': 'cdn-cache; desc=REVALIDATE, edge; dur=85, origin; dur=35, ak_p; desc="1694349122490_389631018_485543705_11957_9607_71_86_-";dur=1', 'Link': '<https://www.nseindia.com/assets/webfonts/fa-brands-400.woff2>;rel="preload";as="font";type="font/woff2";crossorigin,<https://www.nseindia.com/assets/webfonts/fa-solid-900.woff2>;rel="preload";as="font";type="font/woff2";crossorigin, <https://www.google-analytics.com>;rel="preconnect"', 'Strict-Transport-Security': 'max-age=31536000 ; includeSubDomains ; preload'},
'history': [],
'raw': <urllib3.response.HTTPResponse object at 0x151135b40>,
'reason': 'Unauthorized',
'request': <PreparedRequest [GET]>,
'status_code': 401,
'url': 'https://www.nseindia.com/api/quote-equity?symbol=SWSOLAR'}