python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

API KEY Error when fetching Wallet address

Open kadnan opened this issue 2 years ago • 1 comments

Describe the bug I am using the below code to fetch the USDR wallet addresss:

addr = client_live.get_deposit_address(coin='USDT',network='TRX')

but it gives error:

addr = client_live.get_deposit_address(coin='USDT',network='TRX')
  File "/Users/AdnanAhmad/.pyenv/versions/3.9.4/lib/python3.9/site-packages/binance/client.py", line 2742, in get_deposit_address
    return self._request_margin_api('get', 'capital/deposit/address', True, data=params)
  File "/Users/AdnanAhmad/.pyenv/versions/3.9.4/lib/python3.9/site-packages/binance/client.py", line 364, in _request_margin_api
    return self._request(method, uri, signed, **kwargs)
  File "/Users/AdnanAhmad/.pyenv/versions/3.9.4/lib/python3.9/site-packages/binance/client.py", line 315, in _request
    return self._handle_response(self.response)
  File "/Users/AdnanAhmad/.pyenv/versions/3.9.4/lib/python3.9/site-packages/binance/client.py", line 324, in _handle_response
    raise BinanceAPIException(response, response.status_code, response.text)
binance.exceptions.BinanceAPIException: APIError(code=-2015): Invalid API-key, IP, or permissions for action.

It gives error on the following line:

addr = client_live.get_deposit_address(coin='USDT',network='TRX')

All I want to fetch addresses

kadnan avatar Apr 28 '24 19:04 kadnan

I personally had much less trouble using self generated API keys.

  1. openssl genrsa -out your-prv-key.pem 2048
  2. openssl rsa -in your-prv-key.pem -pubout -outform PEM -out your-pub-key.pem
  3. Register the key in your API Management - I recommend to use Unrestricted IP except for when you have a static ip. In that case allow the ip from curl -4 ifconfig.me && echo
  4. Enable Reading should do the job but possibly you must activate more as well.
import os
from pathlib import Path
from binance.client import Client

client = Client(
    api_key='<your api key>',
    private_key=Path(
        os.path.dirname(os.path.realpath(__file__)),
        'your-prv-key.pem'
    )
)

addr = client.get_deposit_address(coin='USDT',network='TRX')

trueToastedCode avatar Nov 26 '24 15:11 trueToastedCode