0
curl "https://www.nseindia.com/api/quote-derivative?symbol=BANKNIFTY"

I am trying this code in my terminal but an "Access Denied" error pops up every time I run it:

My command output

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

2 Answers2

2

that website runs on a user-agent whitelist, and curl is not on their whitelist. seems the easiest way to get around it is to fake the user-agent, an example of a whitelisted user-agent is Chrome/79,

 curl --user-agent 'Chrome/79' 'https://www.nseindia.com/api/quote-derivative?symbol=BANKNIFTY'

protip: that website loads much faster if you add the argument --compressed - it gzips really well, here it goes from ~1400 milliseconds response time to ~600 milliseconds response time (on a shitty 4G connection from Tjøme, Norway :P )

hanshenrik
  • 19,904
  • 4
  • 43
  • 89
-1

That script i think uses variables from that spesific website so therefore variables is undefined when you run it in you terminal, try to run it in the web console instead.

Noah.Ehrnstrom
  • 172
  • 1
  • 12
  • See if maybe one of these will help: https://askubuntu.com/questions/1102985/how-to-debug-curl-access-denied , https://stackoverflow.com/questions/12399087/curl-to-access-a-page-that-requires-a-login-from-a-different-page/12399176 – Noah.Ehrnstrom Jan 19 '20 at 10:58
  • it has nothing to do with variables. it just runs on a User-Agent whitelist, and curl is not on their whitelist. check my answer below~ – hanshenrik Jan 19 '20 at 12:31