Not able to purge cache with python

Hello all!
I’m trying to automate some routine work, so I decided to use Python’s requests library.
The main idea is to make possible to purge cache. Interesting, that I’m able to do it with curl request, but with Python I’m getting error:

400 Client Error: Bad Request for url: https://api.cloudflare.com/client/v4/zones/3c6531d61a409bbe05393dcacb1203df/purge_cache

My curl request, that works:

curl -X POST “https://api.cloudflare.com/client/v4/zones/zoneID/purge_cache
-H “Content-Type:application/json”
-H “Authorization: Bearer tokenID”
–data ‘{“hosts”: ["host1.example.com", “host2.example.com”]}’

My python code, that doesn’t work:

def prepare_request_body(domains: list) → dict:
return {“hosts”: domains}

def prepare_headers(cloudflare_token: str) → dict:
return {
“Content-type”: “application/json”,
“Authorization”: "Bearer " + cloudflare_token
}

def generate_cloudflare_url(prefix: str, zone_id: str, suffix: str):
return prefix + ‘/’ + zone_id + ‘/’ + suffix

def make_request(url: str, headers: dict, body: dict) → dict:
try:
response = requests.post(
url=url,
headers=headers,
data=body
)
response.raise_for_status()
return {
“error”: False,
“message”: “Request finished”,
“response”: response.text,
“status_code”: response.status_code
}

For debug information, I’ve printed generated headers and body:

Headers: {‘Content-type’: ‘application/json’, ‘Authorization’: ‘Bearer tokenHere’}
Body: {‘hosts’: [’host1.example.com’, ‘host2.example.com’]}

What’s wrong with my code?

P.S. Sorry for unformatted text - no possibility to format correctly code blocksPreformatted text