user12736933
user12736933

Reputation:

Access Denied when accessing site using curl

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

Upvotes: 0

Views: 6183

Answers (2)

hanshenrik
hanshenrik

Reputation: 21513

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 )

Upvotes: 2

noah.ehrnstrom
noah.ehrnstrom

Reputation: 182

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.

Upvotes: -1

Related Questions