Get 400 from requests.post in send_message because parameter should be json=data, not data=data
Pyhton 3.11.2 on Debian, was getting constant 400 when trying to do anything, e.g.
400 Client Error: Bad Request for url: https://graph.facebook.com/v20.0/12345678/messages
Turned out to be because the requests.post() parameter should be named json not data
i.e.
response = requests.post(
url, json=data, headers=headers, timeout=10
) # 10 seconds timeout as an example
Sorry don't have time to do a PR for this :(
is 12345678 your PHONE_NUMBER_ID? where can i find that? i think thats the only issue i have since im also just receiving 400 client errors even after your fix
I have the same error: root - ERROR - Request failed due to: 400 Client Error: Bad Request for url: https://graph.facebook.com/v21.0/462219310303970/messages werkzeug - INFO - 127.0.0.1 - - [08/Oct/2024 15:50:35] "POST /webhook HTTP/1.1" 200 -
1 - Send message from meta - OK 2 - Webhook - OK 3 - Send Message from test in webhook page meta - error 400 client error 4 - When send message from whatsapp - error 400 client error
How can i fix this?
my problem was my .env file, i dont know what i did wrong, but for some reason whenever i updated it and saved it with the new keys, for some reason the file was completely ignored and used a previous version of the file that, as far as i know, didnt exist anymore. maybe something has not updated, clear your cache and try again