I am trying to use the gocardless_pro API and I keep getting a key error which am not sure how to resolve.
Below is my code
import os
import gocardless_pro
client = gocardless_pro.Client(
access_token=os.environ['testing123'],
environment='sandbox'
)
Running this code alone throws the below key error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-23-2b23701d8478> in <module>
2 # We recommend storing your access token in an
3 # environment variable for security
----> 4 access_token=os.environ['testing123'],
5 # Change this to 'live' when you are ready to go live.
6 environment='sandbox'
~\Anaconda3\lib\os.py in __getitem__(self, key)
676 except KeyError:
677 # raise KeyError with the original key value
--> 678 raise KeyError(key) from None
679 return self.decodevalue(value)
680
KeyError: 'testing123'
Here is the link am following: https://developer.gocardless.com/getting-started/api/making-your-first-request/
You have two options.
Change the line
access_token=os.environ['sandbox_-VghfQfP7nNxN_arDMfAMKF9qKdyLA05teLqGDky']
toaccess_token='sandbox_-VghfQfP7nNxN_arDMfAMKF9qKdyLA05teLqGDky'
Set an environment variable with your token value, then reference that like so:
Do this first from command prompt:
Then reference token from Python like so: