python-whatsapp-bot icon indicating copy to clipboard operation
python-whatsapp-bot copied to clipboard

Get 400 from requests.post in send_message because parameter should be json=data, not data=data

Open mozboz opened this issue 1 year ago • 3 comments

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 :(

mozboz avatar Aug 06 '24 11:08 mozboz

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

A00826925 avatar Aug 16 '24 02:08 A00826925

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?

manifestt avatar Oct 08 '24 19:10 manifestt

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

A00826925 avatar Oct 09 '24 04:10 A00826925