Authentication not working for zone cache purge endpoint

I’ve been using Cloudflare API for some time now uploading images, but now am trying to figure out how I can purge cache via API and am having issues with authentication. My code below (Python):

import requests
from configs.credentials import cloudflare

cf_url_cache = "{}/purge_cache".format(

def clear_cloudflare_cache(url):
    payload = {
        "files": [url]
    purge =, data=payload, headers={
        "Content-Type": "application/json",
        "X-Auth-Email": "{my_email}",
        "X-Auth-Key": cloudflare["api_key"]
    if purge.ok:
        print("successfully purged URL cache")
        print("Purging Cloudflare cache request didn't succeed: {}".format(purge.content))

url = "https://my_url"

I tried using Bearer Token and Email and Key - both result in the same error.
Bearer Token auth method works fine with the image upload endpoint.

Anybody could give me a hand?