Howdy All - First time Cloudflare user…
I’ve seen lots of recentish posts on this issue, but can’t get around it.
In short, getting “Cloudflare.exceptions.CloudFlareAPIError: method_not_allowed” using the API to update a DNS record.
– The simplified code:
import Cloudflare
ZONE=“mydom”
cf = Cloudflare.Cloudflare(email=‘myemail’, token=GLOBAL_API_KEY)
zones = cf.zones.get(params = {‘name’:ZONE,‘per_page’:1})
zone = zones[0]
zone_id = zone[‘id’]
dns_record = {‘name’:‘BLAH’, ‘type’:‘A’, ‘ttl’: 120, ‘content’: ‘192.168.1.7’}
cf.zones.dns_records.put(zone_id, data=dns_record)
I’ve dabbled w/bearer tokens and the ttl and various hints and hacks on other posts. Yet, no joy yet.
Any ideas?
simon
April 2, 2022, 3:57pm
#2
This is likely an issue with your code or the library itself. The best thing to do is to try the PUT operation via a tool like cURL:
https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
curl -X PUT "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \
-H "X-Auth-Email: [email protected] " \
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"example.com","content":"127.0.0.1","ttl":3600,"proxied":false}'
If it works there, then you can be sure your token details and API parameters are good - you’ll then need to look deeper into your code.
1 Like
It sounds like the Python wrapper is not supported here.
simon
April 5, 2022, 8:35am
#4
The best place to report an issue with the Python wrapper would be on the official issues page for that project - but before you do that - it’s best to debug the way I have described by making sure your API details are working.
If you’ve confirmed your API details are working, then you could report the issue with steps to reproduce on github:
1 Like
Yes, I did’nt realize that. Thanks. I have done so.
I raised an issue there on the lack of clarity of error msgs and got a quick answer.
It turns out though, I was completely wrong in my usage of the function - here’s the fix for others stumbling:
The last line of the code should simply be:
cf.zones.dns_records.put(my_zone_id, dns_record_id, data=dns_record)))
Thanks for your help and time
1 Like