Vonage / vonage-python-sdk

Vonage Server SDK for Python. API support for Voice, SMS, WhatsApp, Verify (2FA), Video Meetings and more.
https://developer.vonage.com
Apache License 2.0
185 stars 112 forks source link

vonage.errors.AuthenticationError: Authentication failed. Check you're using a valid authentication method. #257

Closed AbrahamMialma closed 3 months ago

AbrahamMialma commented 1 year ago

Hola tengo este error : vonage.errors.AuthenticationError: Authentication failed. Check you're using a valid authentication method.

Linux xubuntu 22.04

Python 3.10

pip3 install vonage

Cuando trato de ejecutar el siguiente codigo :

#################################### Codigo #############################################

import os from os.path import join, dirname

VONAGE_APPLICATION_ID = "f6e2b6af-2610-408d-99f9-c41e2248e03d" VONAGE_APPLICATION_PRIVATE_KEY_PATH = "/home/android/Proyectos/Corato_V2/private.key"

TO_NUMBER = ** FROM_NUMBER = **

import vonage

client = vonage.Client( application_id=VONAGE_APPLICATION_ID, private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,

)

client.messages.send_message({

"channel": "whatsapp", "message_type": "text", "to": "**", "from": "***", "text": "This is a WhatsApp text message sent using the Vonage Messages API",

})

-----https://github.com/Vonage/vonage-python-code-snippets/blob/main/messages/whatsapp/send_text.py

$ python3 send_text.py

#######################################################################################

Ya intente con key y secret pero no funciona, que estoy haciendo mal ???

Gracias de antemano.

Stack trace :

Traceback (most recent call last): File "/home/android/Downloads/ejemplos_vonage/messages/whatsapp/send_text.py", line 23, in client.messages.send_message( File "/home/android/Downloads/ejemplos_vonage/env/lib/python3.10/site-packages/vonage/messages.py", line 25, in send_message return self._client.post( File "/home/android/Downloads/ejemplos_vonage/env/lib/python3.10/site-packages/vonage/client.py", line 231, in post return self.parse( File "/home/android/Downloads/ejemplos_vonage/env/lib/python3.10/site-packages/vonage/client.py", line 277, in parse raise AuthenticationError("Authentication failed. Check you're using a valid authentication method.")

maxkahan commented 1 year ago

Hi, to use WhatsApp as a message channel for the Messages API, you must first register a WhatsApp Business Account to be associated with the WhatsApp messages you send. WhatsApp also have to verify that your business is legitimate, which gives you a green tick. You can read more about this here: https://developer.vonage.com/en/messages/concepts/whatsapp

You can register for a WhatsApp account with Vonage in the developer dashboard.

Hope this helps!

dlewis2017 commented 7 months ago

I've gotten this issue as well but when using Messages API to send an SMS. I think I've narrowed it done to an issue with the application_id but not sure. Created another issue here in case it's different from this one.

peterscardera commented 3 months ago

Hi! Im getting this auth error as well with the Voice api. I made sure the application_id and all other secrets are correct. It initially works but after a certain amount of time I receive the following when trying:

ERROR: Error when triggering call: Authentication failed. Traceback (most recent call last): File "/app/services/vonage_service.py", line 69, in trigger_vonage_call response = vonage_client.voice.create_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/vonage/voice.py", line 29, in create_call return self._client.post( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/vonage/client.py", line 295, in post return self.parse( ^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/vonage/client.py", line 395, in parse raise AuthenticationError("Authentication failed.") vonage.errors.AuthenticationError: Authentication failed.

A restart of the backend makes it temporarily work again

maxkahan commented 3 months ago

Hi, this is quite a general error that's returned in a lot of cases. My suspicion is that the JWT used by your application is expiring as it has a default timeout of 15 minutes. You can change this using the auth method in the client class by setting a value for exp as an argument.

Hope this helps!

maxkahan commented 3 months ago

Note on the above: a new JWT is generated every request, but if an individual request takes time or isn't actioned due to async code etc., this can cause this problem. I'll close this issue now as the original reason it was kept open was to signpost the need to register a WhatsApp business channel, I think it's better now to have people create their own issues when they run into them.