简体   繁体   English

使用Python的Coinbase API(PyCharm)

[英]Coinbase API using Python (PyCharm)

I am trying to use Coinbase's API to get my wallet info to eventually make transactions using Python. 我正在尝试使用Coinbase的API获取我的钱包信息,以便最终使用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'. 运行后,出现错误->'NameError:名称'api_key'未定义'。 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. 我知道应该通过Coinbase设置API密钥和API Secret(我已经完成了),甚至将它们都放在“客户端”括号中。 Cany anyone tell me what I am doing wrong or guide me to successfully use my Coinbase API in Python? 谁能告诉我我做错了什么,还是可以指导我成功地在Python中使用Coinbase API?

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 该错误专门告诉您api_key

The error is self explanatory, your variable api_key and api_secret are undefined, thus the NameError exception. 该错误是不言自明的,您的变量api_keyapi_secret未定义,因此出现NameError异常。

  1. 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) 您可以通过对Coinbase提供的密钥和秘密进行硬编码来替换api_key (它应采用随机生成的长字符串的形式)

  2. Verify that you can indeed perform an API call on Coinbase 验证您确实可以在Coinbase上执行API调用

  3. 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 现在,删除硬编码版本并改用环境变量(这将防止您将密钥错误地发布到公共存储库中) 如何对API密钥使用环境变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM