python-binance: TESTNET: binance.exceptions.BinanceAPIException: APIError(code=-2008): Invalid Api-Key ID.
Describe the bug I tried to connect to the binance testnet and to get the account status, but got the following error:
File “/home/h/anaconda3/envs/pairTrading/lib/python3.9/site-packages/binance/client.py”, line 2065, in get_account_status return self._request_margin_api(‘get’, ‘account/status’, True, data=params) File “/home/h/anaconda3/envs/pairTrading/lib/python3.9/site-packages/binance/client.py”, line 365, in _request_margin_api return self._request(method, uri, signed, **kwargs) File “/home/h/anaconda3/envs/pairTrading/lib/python3.9/site-packages/binance/client.py”, line 316, in _request return self._handle_response(self.response) File “/home/h/anaconda3/envs/pairTrading/lib/python3.9/site-packages/binance/client.py”, line 325, in _handle_response raise BinanceAPIException(response, response.status_code, response.text) binance.exceptions.BinanceAPIException: APIError(code=-2008): Invalid Api-Key ID.
I found out, that when I call client.get_account_status(), the client connects to the real binance api and not to the testnet api because it doesn’t switch from the real url to the testnet url:
def _create_margin_api_uri(self, path: str, version: str = MARGIN_API_VERSION) -> str:
return self.MARGIN_API_URL + '/' + version + '/' + path
To compare with other requests that works:
def _create_api_uri(self, path: str, signed: bool = True, version: str = PUBLIC_API_VERSION) -> str:
url = self.API_URL
if self.testnet:
url = self.API_TESTNET_URL
v = self.PRIVATE_API_VERSION if signed else version
return url + '/' + v + '/' + path
To Reproduce client = Client(config.api_key, config.secret_key, testnet=True) client.get_account_status()
Expected behavior Response from the Testnet.
Environment (please complete the following information):
- Python version: 3.9
- Virtual Env: conda
- OS: RHEL 8.4
- python-binance version: 1.0.15
Logs or Additional context Add any other context about the problem here.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 23 (5 by maintainers)
Thank you erik404, I will go through your changes and check them out