gpt4 book ai didi

python-3.x - 属性错误 : 'NoneType' object has no attribute 'encode' (Binance)

转载 作者:行者123 更新时间:2023-12-05 04:50:58 25 4
gpt4 key购买 nike

我希望这个连接到 Binance 并获取我的帐户详细信息的简单脚本能够使用 python-binance 工作库(版本:0.7.9)开箱即用,但似乎没有。我能够连接到 API 并获取比特币的价格,因此我确信错误不是这个。

import os

from binance.client import Client
from binance.websockets import BinanceSocketManager
from twisted.internet import reactor

# Get keys
api_key = os.environ.get('binance_api')
api_secret = os.environ.get('binance_secret')

# Connect to Binance
client = Client(api_key, api_secret)
print(client.get_account())

出现以下错误。

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-9c56ae96674c> in <module>
----> 1 print(client.get_account())

~/.local/lib/python3.8/site-packages/binance/client.py in get_account(self, **params)
1765
1766 """
-> 1767 return self._get('account', True, data=params)
1768
1769 def get_asset_balance(self, asset, **params):

~/.local/lib/python3.8/site-packages/binance/client.py in _get(self, path, signed, version, **kwargs)
235
236 def _get(self, path, signed=False, version=PUBLIC_API_VERSION, **kwargs):
--> 237 return self._request_api('get', path, signed, version, **kwargs)
238
239 def _post(self, path, signed=False, version=PUBLIC_API_VERSION, **kwargs):

~/.local/lib/python3.8/site-packages/binance/client.py in _request_api(self, method, path, signed, version, **kwargs)
200 uri = self._create_api_uri(path, signed, version)
201
--> 202 return self._request(method, uri, signed, **kwargs)
203
204 def _request_withdraw_api(self, method, path, signed=False, **kwargs):

~/.local/lib/python3.8/site-packages/binance/client.py in _request(self, method, uri, signed, force_params, **kwargs)
178 # generate signature
179 kwargs['data']['timestamp'] = int(time.time() * 1000)
--> 180 kwargs['data']['signature'] = self._generate_signature(kwargs['data'])
181
182 # sort get and post params to match signature order

~/.local/lib/python3.8/site-packages/binance/client.py in _generate_signature(self, data)
133 ordered_data = self._order_params(data)
134 query_string = '&'.join(["{}={}".format(d[0], d[1]) for d in ordered_data])
--> 135 m = hmac.new(self.API_SECRET.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256)
136 return m.hexdigest()
137

AttributeError: 'NoneType' object has no attribute 'encode'

检查 docs ,我看不出我做错了什么。由于调试日志表明错误可能在 binance api 中,但我不确定,因为这是一项基本功能,应该可以正常工作。

感谢您的帮助。

最佳答案

key 未正确导入,请检查 os.environ 中的 'binance_api'。将 set -gx ENV_NAME=value 添加到 ~/.config/fish/config.fish

关于python-3.x - 属性错误 : 'NoneType' object has no attribute 'encode' (Binance),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67106239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com