TESTNET: binance.exceptions.BinanceAPIException: APIError(code=-2008): Invalid Api-Key ID.

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
claude-eric-steinercommented, Jun 22, 2022

Thank you erik404, I will go through your changes and check them out

0reactions
hamishkrcommented, Jul 4, 2022

on the Spot Testnet I don’t think /sapi/* endpoints are available including Wallet Endpoints

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binance Future api : APIError(code=-2015): Invalid API-key, IP ...
In my code, I have a "client" variable: client = Client(config.API_KEY, config.API_SECRET, tld='us'). and, here's the thing:.
Read more >
why do I see this error "Invalid API-key, IP, or permissions for ...
This is a common issue and many asked from API users. The reason is just as said from error message: API key is...
Read more >
Errors with Binance connection - Quantower Help
Here is the list of the most common errors and issues with Binance Futures /Spot connections: ​Error "Invalid API-key, IP, or permissions for...
Read more >
How to Test My Functions on Binance Testnet
Follow the official Spot API Key documentation to replace the API endpoint URLs ... Log in to your Binance testnet account on the...
Read more >
GET /eapi/v1/time - Change Log – Binance API Documentation
{ "code": -1121, "msg": "Invalid symbol." } Specific error codes and messages defined in Error Codes. General Information on Endpoints. For GET endpoints, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found