POST api not working with python requests

Hi guys,

I am writing a program in python + flask, which among other things uses python requests to interact with cloudflare api. However I am having a little difficulty getting the POST command to create a new dns record.

So this works:
requests.get(url, headers=headers) # where the url is a string and the headers is a dict obj

And this works:
requests.put(url + ‘/’ + item[‘id’], headers=headers, json=data) # data is a dict that is sent as json

But this wont work:, headers=headers, json=data)

All the url, headers and data fields are assembled in the same function before being passed to the requests method, so I’m not sure what is going wrong. I have gotten maybe 2 or 3 ‘200’ responses that don’t actually work, but mostly just get ‘400’ bad request.

Any ideas?

Try printing the request.body, it should contain more info.

I feel like such an idiot! :man_facepalming:
I flashed the response.text message and it said the record already existed…
I have 2 domains…

Thanks for the help, seems it was working the whole time. :laughing:

1 Like