Skip to content Skip to sidebar Skip to footer

Twilio Auth Windows Enviro Variables

I'm putting together some python code to move and then delete recordings from Twilio. There's plenty of documentation online to help with the script but the documentation says that

Solution 1:

On my Windows 10 machine - in the new variable window - it asks for 'variable name' and 'variable value'.

I don't have Windows 10 but I'm showing you on Widnows 7, it's probably the same interface to add system variables.

So you need to set two 'Environment Variables' > 'System Variables':

First one:

  • 'variable name' put this: TWILIO_ACCOUNT_SID
  • 'variable value' put your twilio account sid which looks something like this: AC0123456789abcdefabcdefabcdefabcd

enter image description here

Second one:

  • 'variable name' put this: TWILIO_AUTH_TOKEN
  • 'variable value' put your twilio auth token which looks something like this: 0123456789abcdefabcdefabcdefabcd

enter image description here

now back to your code change this:

account_sid = "{{ myaccountSID }}"auth_token  = "{{ myToken }}"

to this:

account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
auth_token  = os.environ.get('TWILIO_AUTH_TOKEN')

If you had a command window open, close it. You need to open a new command window in order to pick up the new environment variables.

Solution 2:

Twilio evangelist here.

By default the TwilioRestClient object in the Twilio Python helper library looks for environment variables named TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN inside the current environment. Here is a post that describes how to set up environment variables on Windows:

https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

So to set the environment variable for your Account Sid you would open a command prompt and enter:

c:\>set TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXX

Keeping credentials in environment variables is a good way to keep those credentials safe and help prevent something like you accidentally checking them into source control.

If you'd rather not use environment variables you can also provide the credentials directly to the library via the constructor:

from twilio.rest import TwilioRestClient

ACCOUNT_SID = "AXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

Hope that helps.

Post a Comment for "Twilio Auth Windows Enviro Variables"