Home > OS >  Downloading images from wikipedia gives forbidden error due to User Agent policy
Downloading images from wikipedia gives forbidden error due to User Agent policy

Time:10-27

I am trying to scrape some actors images from Wikipedia using python and constantly get the following error HTTPError: 403 Client Error: Forbidden. Please comply with the User-Agent policy: https://meta.wikimedia.org/wiki/User-Agent_policy for url: https://upload.wikimedia.org/wikipedia/commons/0/0a/Christian_Bale-7837.jpg

The code I am using is as follows:

url = 'https://en.wikipedia.org/wiki/'
headers = {'User-Agent': 'copied user agent that came out when I googled it'}
response = requests.get(url, headers)

I can post the entire code if the problem clearly is not from the code above.

I googled it for the past 30 minutes. Wikipedia has a documentation page about the User Agent and I followed their steps to do this, but it still did not work.

CodePudding user response:

Just add a comment saying what the code is meant to do at the end of user agent

CodePudding user response:

It should be requests.get(url, headers=headers).

That said, don't just put in some random string you pulled from Google as the user agent. That's impolite and might get you banned if you generate significant traffic. Indicate who you are and what tool you are using, as asked in the user-agent policy. Something like NicoBot/0.1 ([email protected]) would work.

  • Related