0

I have been trying to download file from this URL using given code but getting following error: HTTPError: HTTP Error 403: Forbidden. Further how can I download multiple files by changing url from */2020/SCBSEALL0207.zip to */2020/SCBSEALL0101.zip

import requests
url = 'https://www.bseindia.com/BSEDATA/gross/2020/SCBSEALL0207.zip'

r = requests.get(url)
with open("Bse_20200702", "wb") as code:
    code.write(r.content)

urllib.request.urlretrieve(url, "Bse_20200702.zip")```
Neo
  • 21
  • 3
  • 2
    The 403: Forbidden response means you do not have the proper permissions to access the resource. Since you are passing no headers in the request there is no way for the server to properly identify your access, and thus defaults to a 403 response. – gallen Jul 14 '20 at 17:47
  • @gallen, That's not true, did you follow the link to see? – Chris Jul 14 '20 at 17:48
  • 2
    @Chris It is true. When you follow the link via browser, there are headers attached. Via the code, there are no headers. – gallen Jul 14 '20 at 17:49
  • There is no authentication, so it's not going to be a permission issue. Perhaps a better comment would be to point towards basic header construction. – Chris Jul 14 '20 at 17:53
  • @Chris If this wasn't an authentication of request issue, then it would be a 401 or a 400. 403 is distinctly an error response tied to lack of permission. To be clear: Authentication isn't always authentication of user. There are multiple ways to authenticate a request to a server that aren't username/password/token related. My initial comment "Since you are passing no headers". And second "Via code, there are no headers". That's two instances of pointing towards headers being needed. So I have already done what you suggest. – gallen Jul 14 '20 at 18:00
  • 1
    Hey does this help https://stackoverflow.com/questions/9419162/download-returned-zip-file-from-url ? – Y4glory Jul 14 '20 at 18:02
  • @Y4glory I tried solutions from the the post but getting same error: – Neo Jul 15 '20 at 03:17
  • I tried the get request from Postman it gets some data. Maybe there are some headers to be included – Y4glory Jul 15 '20 at 05:33
  • I am new to python(programing in general) , so asking an amateur question, when you say header to be included do you mean like more libraries or some thing else? Also if you can point me in right dirrection to understand headers more. Thank you! – Neo Jul 15 '20 at 08:23
  • Headers in this context is referencing HTTP request headers. I suggest doing some research on HTTP requests and responses to get a better understanding of how what you are trying to do works. – gallen Jul 15 '20 at 08:39

0 Answers0