telstra / MessagingAPI-SDK-python

Telstra Messaging SDK - Python Library

Home Page:https://dev.telstra.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NameError: name 'configuration' is not defined

noelje opened this issue · comments

commented

I'm getting a "name 'configuration' is not defined" error. I followed the instructions carefully, and unsure of why this is causing an issue.

Running on:
Python3 Virtual Environment (installed all the packages here)
Device: 2011 Macbook Pro (8,1)
OS: 64bit Mac OS X 10.13.6 17G14042
Kernel: x86_64 Darwin 17.7.0
Intel Core i5-2435M @ 2.40GHz
Bash

(apienv) bash-5.1$ pip --version
pip 21.2.4 from /Users/noel/telstra/apienv/lib/python3.9/site-packages/pip (python 3.9)
(apienv) bash-5.1$ python3 app.py
Traceback (most recent call last):
  File "/Users/noel/telstra/MessagingAPI-SDK-python/app.py", line 9, in <module>
    configuration.host = "https://tapi.telstra.com/v2"
NameError: name 'configuration' is not defined

What the app.py looks like:

(apienv) bash-5.1$ cat app.py
from __future__ import print_function
import time
import Telstra_Messaging
from Telstra_Messaging.rest import ApiException
from pprint import pprint


# Defining host is optional and default to https://tapi.telstra.com/v2
configuration.host = "https://tapi.telstra.com/v2"
# Create an instance of the API class
api_instance = Telstra_Messaging.AuthenticationApi(Telstra_Messaging.ApiClient(configuration))
client_id = 'DOF8UIcPjmM8ciq1eqGIBzAYvBCG67Pt' # str |
client_secret = 'GDTGeVnP37FoaO14' # str |
grant_type = 'client_credentials' # str |  (default to 'client_credentials')
scope = 'NSMS' # str | NSMS (optional)

try:
    # Generate OAuth2 token
    api_response = api_instance.auth_token(client_id, client_secret, grant_type, scope=scope)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling AuthenticationApi->auth_token: %s\n" % e)
(apienv) bash-5.1$

DId a grep search for the word "configuration" but my suspicion is that there is something wrong with the API URL.

the configuration object does not exist, you are trying to use an object which has yet to be defined.

This is how I use the API:

api_instance = Telstra_Messaging.AuthenticationApi()
api_response = api_instance.auth_token(
   settings.TELSTRA_CLIENT, settings.TELSTRA_SECRET, "client_credentials"
)

# Configure OAuth2 access token for authorization: auth
configuration = Telstra_Messaging.Configuration()
configuration.access_token = api_response.access_token

api_instance = Telstra_Messaging.MessagingApi(Telstra_Messaging.ApiClient(configuration))
payload = Telstra_Messaging.SendSMSRequest(
    to=to,
    body=sms_text,
    _from=settings.SMS_NAME,
    validity=settings.SMS_VALIDITY,
    notify_url=self.callback_url,
)
api_response = api_instance.send_sms(payload)

I've obviously got some stuff there which you'll need to change, but hopefully should help you out a bit