Changing SRV record w/ cloudflare API (python)

Hello!

I’m trying to use the cloudflare api to automatically update a SRV record for a minecraft server that is being reverse proxied by ngrok.
What I’m doing right now is

import urllib.request, json, subprocess
get_ipython().system_raw(’./ngrok authtoken (authtoken) && ./ngrok tcp 25565 &’)
with urllib.request.urlopen(‘http://localhost:4040/api/tunnels’) as response:
data = json.loads(response.read().decode())
(host, port) = data[‘tunnels’][0][‘public_url’][6:].split(’:’)
print(port, host)
subprocess.check_output([‘bash’,‘flare.sh’, port, host])

Inside flare.sh is

curl -X PUT “https://api.cloudflare.com/client/v4/zones/(zone id)dns_records/(dns id)”
-H “X-Auth-Email: *******@********.com”
-H “X-Auth-Key: 00000000000000”
-H “Content-Type: application/json”
–data ‘{“type”: “SRV”, “data”: {“service”: “_minecraft”, “proto”: “_tcp”, “name”: “mc”, “priority”: 1, “weight”: 5, “port”: $1, “target”: “$2”}}’

However, this returns

{“result”:null,“success”:false,“errors”:[{“code”:9207,“message”:“Failed to parse request body, content-type must be application/json”}],“messages”:}

I know that there’s a way to access the api through python, but I’m not sure how (don’t know any programming). The bash script also works properly when I run it and replace the values of $1 and $2 with the correct port and target values.

That is rather a Python/Bash question than Cloudflare related I am afraid.

You better take this to StackOverflow. The error message would suggest your JSON document is not properly formatted. You might want to debug that in the usual way.