I am trying to get my spot testnet account information, here is my code:
import base64
import requests
import time
from cryptography.hazmat.primitives.serialization import load_pem_private_key
# test
test_keys_root_path = 'test/keys/root/path '
# test ed25519
test_ed25519_api_key_path = test_keys_root_path + 'Ed25519/api-key'
test_ed25519_pub_key_path = test_keys_root_path + 'Ed25519/pub-key.pem'
test_ed25519_prv_key_path = test_keys_root_path + 'Ed25519/prv-key.pem'
with open(test_ed25519_api_key_path) as f:
test_ed25519_api_key = f.read()
with open(test_ed25519_pub_key_path) as f:
test_ed25519_pub_key = f.read()
with open(test_ed25519_prv_key_path, 'rb') as f:
test_ed25519_prv_key = load_pem_private_key(data=f.read(), password=None)
if __name__ == '__main__':
params = {
# "symbol": "BTCDUSDT",
}
timestamp = int(time.time() * 1000)
params['timestamp'] = timestamp
payload = '&'.join([f'{param}={value}' for param, value in params.items()])
signature = base64.b64encode(test_ed25519_prv_key.sign(payload.encode('ASCII')))
params['signature'] = signature
headers = {
'X-MBX-APIKEY': test_ed25519_api_key.replace('\n', ''),
}
response = requests.get(
'https://testnet.binance.vision/api/v3/account',
headers=headers,
data=params
)
print(f'status_code: {response.status_code}\n')
print(f'headers: {response.headers}\n')
print(f'text: \n{response.text}\n')
print(f'json: \n{response.json()}\n')
I keep getting http 403 error, and really dont konw what to do, can anyone help? Thanks.