Reputation: 1
I am trying to simulate the voice call using vonage voice api. I am trying to do that my using python. I created an .env file and updated the values of app id and private key value and not path (not sure where to get it).
this is the below code written:
#!/usr/bin/env python3
import os
from os.path import join, dirname
from pprint import pprint
import vonage
from dotenv import load_dotenv
dotenv_path = join(dirname(__file__), "../.env")
load_dotenv(dotenv_path)
VONAGE_APPLICATION_ID = os.environ.get("VONAGE_APPLICATION_ID")
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get("VONAGE_APPLICATION_PRIVATE_KEY_PATH")
FROM_NUMBER = os.environ.get("FROM_NUMBER")
TO_NUMBER = os.environ.get("TO_NUMBER")
client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
response = client.voice.create_call({
'to': [{'type': 'phone', 'number': TO_NUMBER}],
'from': {'type': 'phone', 'number': FROM_NUMBER},
'answer_url': ['https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json']
})
pprint(response)
the error i got was as follows:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/vonage/client.py", line 396, in _generate_application_jwt
return self._jwt_client.generate_application_jwt(self._jwt_claims)
AttributeError: 'Client' object has no attribute '_jwt_client'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "make-an-outbound-call.py", line 24, in <module>
'answer_url': ['https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json']
File "/usr/local/lib/python3.7/site-packages/vonage/voice.py", line 28, in create_call
return self._client.post(self._client.api_host(), "/v1/calls", params or kwargs, auth_type=Voice.auth_type)
File "/usr/local/lib/python3.7/site-packages/vonage/client.py", line 246, in post
self._request_headers['Authorization'] = self._create_jwt_auth_string()
File "/usr/local/lib/python3.7/site-packages/vonage/client.py", line 392, in _create_jwt_auth_string
return b"Bearer " + self._generate_application_jwt()
File "/usr/local/lib/python3.7/site-packages/vonage/client.py", line 400, in _generate_application_jwt
'JWT generation failed. Check that you passed in valid values for "application_id" and "private_key".'
vonage.errors.ClientError: JWT generation failed. Check that you passed in valid values for "application_id" and "private_key".```
Upvotes: 0
Views: 128