Reputation: 31
I am trying to use Coinbase's API to get my wallet info to eventually make transactions using Python. Below is the 2 lines of code that i have written:
from coinbase.wallet.client import Client
client = Client(api_key, api_secret)
After running, I get the error--> 'NameError: name 'api_key' is not defined'. I know that I am supposed to set up an API Key and API Secret via Coinbase (which I have done already) and even put them both in the 'Client' parenthesis. Cany anyone tell me what I am doing wrong or guide me to successfully use my Coinbase API in Python?
Upvotes: 0
Views: 1262
Reputation: 2473
The error is self explanatory, your variable api_key
and api_secret
are undefined, thus the NameError
exception.
What you can is replace api_key
by hardcoding your key and secret
provided by Coinbase (it should be in the form of a long randomly
generated string)
Verify that you can indeed perform an API call on Coinbase
Now, remove the hardcoded version and use environment variables instead (this will prevent you from publishing your keys to public repositories by mistakes) How to use environment variables for API keys
Upvotes: 1
Reputation: 4770
Make sure you initialize both vars before creating the client
from coinbase.wallet.client import Client
api_key = 'my api key here'
api_secret = 'my api secret'
client = Client(api_key, api_secret)
The error specifically tells you that api_key
is not defined
Upvotes: 1