I'm trying to send a request to pixabay.
Here's my code
import requests
url = 'https://pixabay.com'
header = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36'
}
req = requests.get(url, headers=header)
print(req.status_code)
print(req.headers)
print(req.text)
It won't work(403 error). How can I do to work?
Pixabay has Cloudflare security that requires you to solve a captcha if you connect from a blacklisted IP.
In order to bypass this, you have to first connect via a browser and then copy the headers and cookies into your python script. This works for me, but you have to replace the parts like
__cfduidwhich is your cloudflare fingerprint in order to access the website. Also check that your User-Agent is correct.