Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!)

enter image description here


1 Answers

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=..

like image 191
Vladimir.Shramov Avatar answered Oct 31 '25 10:10

Vladimir.Shramov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!