How to access the API that posses Cloudflare protection with python.

papatsapong jiraroj-ungkun
2 min readDec 22, 2018

--

As you might know that Cloudflare has a DDoS protection mechanism, therefore it is impossible to access the API with Cloudflare protection using traditional requests library.

Example of Cloudflare DDoS protection
This is what you get when accessing such a website with traditional requests library

However, there is a solution to this issue. By using cfscrape, we can requests the data from API with Cloudflare protection.

First of All, you need to download cfscrape. Simply use pip to install it.

pip install cfscrape

After you have successfully install cfscrape, you can start coding your python scripts.

  1. import the library and create a scraper instance.

import cfscrape
scraper = cfscrape.create_scraper()

2. use the scrape to send a request to the web server in the same manner as requests

req = scraper.get(‘http://pokeapi.co/api/v2/pokemon/384/')

3. Run your script and wait for the result.

Now the API is accessible

That’s all for how to access the API that posses Cloudflare protection with python.

Note: I personally don’t suggest to do this every time you face an API with Cloudflare protection. I just do this tutorial for fun and education purpose. If possible please find another similar API without Cloudflare protection.

Find out more information at:

--

--

papatsapong jiraroj-ungkun

A senior student of Faculty of ICT, Mahidol Univesity.Interested in Computer Network field. A newbie in network programming