API cannot add ipv6 in blacklist

Greetings everyone.

I have made a small script that adds any IP in CF blacklist to prevent bot attacks for a website. It is working very well and Ι can even add IP ranges using /24 and so on. However, when I attempt to add ipv6 address, the API return an error with message - “invalid value for ip at position 0: filters.api.IPv6 IP addresses are not supported. We suggest using a /64 CIDR instead”.

I have tried adding /64 as well as /24 and others, but the API is still returning this error. So what’s the correct way to pass an ipv6 IP in the blacklist? I also tried converting ipv6 to 4, but some addresses cannot be converted.

Code used (Python):
url = “https://api.cloudflare.com/client/v4/accounts/…”
payload = ‘[{“ip”: "’ + ip +‘", “comment”: “blocked from script.”}]’
headers = {
‘X-Auth-Email’: ‘[email protected]’,
‘X-Auth-Key’: ‘123…’,
‘Content-Type’: ‘application/json’}
response = requests.request(“POST”, url, headers=headers, data = payload)

Have you tried letting requests convert a dict to JSON?

payload = [{"ip": "<IP>", "comment": "blocked from script."}]
requests.request("POST", url, headers=headers, json=payload)
1 Like

Yes. The response is : “filters.api.invalid_json”.

I also got this error for every other change I’ve tried.