A
A
Asprod2021-11-20 16:24:06
Python
Asprod, 2021-11-20 16:24:06

Content-type must be application/json. cloudflare?

headers={'X-Auth-Key': cloud[3],'X-Auth-Email': cloud[1], "Content-Type": "application/json"}
data = {"type":"A","name":domain[2],"content":ip[0],"ttl":3600,"priority":10,"proxied":False}
requests.post(f"https://api.cloudflare.com/client/v4/zones/{domain[9]}/dns_records", headers=headers, data=data).json()

Returns {'result': None, 'success': False, 'errors': [{'code': 9207, 'message': 'Content-type must be application/json.'}], 'messages': [] }
More strangely, I make requests to other cloudflare apis with the same header and they work. In this case, he behaves strangely

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-11-20
@Asprod

If you need to send json - pass your json object to the json parameter.

requests.post(f"https://api.cloudflare.com/client/v4/zones/{domain[9]}/dns_records", headers=headers, json=data).json()

content-type from headers can also be removed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question