简体   繁体   中英

APIError(code=-2014): API-key format invalid

call to action!

I am struggling in this:

APIError(code=-2014): API-key format invalid

Any suggestion? Many thanks

# Import libraries
import configparser 
from binance.client import Client


# Load keys from config file
config = configparser.ConfigParser()
config.read_file(open(r'C:\\*****my_path****\\secret.cfg'))
test_api_key = config.get('BINANCE', 'TEST_API_KEY')
test_secret_key = config.get('BINANCE', 'TEST_SECRET_KEY')

#ping the server
client.ping()
#get the server time
time_res = client.get_server_time()

# Getting account info
info = client.get_account()  
# Get current products 
products = client.get_products()
#Get all coin info
info = client.get_all_coins_info()

print(info)

--- EDIT: ERROR OUTPUT

Here the error message in output:

[Running] python -u "c:\Users\ssida\OneDrive\Documenti\GitHub\AI7XF205SS\getting_account_info.py"
Traceback (most recent call last):
  File "c:\Users\ssida\OneDrive\Documenti\GitHub\AI7XF205SS\getting_account_info.py", line 16, in <module>
    info = client.get_account()  # Getting account info
  File "C:\Users\ssida\anaconda3\lib\site-packages\binance\client.py", line 1822, in get_account
    return self._get('account', True, data=params)
  File "C:\Users\ssida\anaconda3\lib\site-packages\binance\client.py", line 292, in _get
    return self._request_api('get', path, signed, version, **kwargs)
  File "C:\Users\ssida\anaconda3\lib\site-packages\binance\client.py", line 242, in _request_api
    return self._request(method, uri, signed, **kwargs)
  File "C:\Users\ssida\anaconda3\lib\site-packages\binance\client.py", line 237, in _request
    return self._handle_response()
  File "C:\Users\ssida\anaconda3\lib\site-packages\binance\client.py", line 285, in _handle_response
    raise BinanceAPIException(self.response)
binance.exceptions.BinanceAPIException: APIError(code=-2014): API-key format invalid.

[Done] exited with code=1 in 1.952 seconds

HEre the snapshot of the error message showed me by python terminal > Pylance explain to me that is related on reportMIssing Imports (that i dunno whats mean but ok!)

在此处输入图像描述

I spent few hours debugging right "signature" generation, checking time sync and getting such message. found that it is required to put signature as last api query param:

not working: [https://...]?signature=..&recvWindow=..&timestamp=..

working order: [https://...]?recvWindow =..&timestamp=..&signature=..

Most likely 'TEST_API_KEY' or 'TEST_SECRET_KEY' are wrong or have the wrong format. I had the same problem because the keys were stored in the.env file with quotes

TEST_API_KEY="xxxxxxxxxxxxxxxx" 

and after removing quotes, it worked.

TEST_API_KEY=xxxxxxxxxxxxxxxx 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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