Signed request problem (Python)

Hi! I try to use example SIGNED Endpoint from Binance API Documentation for signed request Get sapi/v1/capital/config/getall in Python Original example uses .pem file which has a secret key. I don’t know how to make pem file and use just → secret_key=‘aTysuid5kjsd…’ instead of access to pem file. The result (?) is an error ““AttributeError: ‘str’ object has no attribute ‘sign’””" My question is it’s because of using just string instead of pem file? If so how to make such a pem file? Can I download it from my Binance Personal Area? Here is my full Python code:
import base64
import requests
import time
from cryptography.hazmat.primitives.serialization import load_pem_private_key

api_key = ‘RNy…’
private_key = ‘p74W…’

params = {}

Timestamp the request

timestamp = int(time.time() * 1000) # UNIX timestamp in milliseconds
params[‘timestamp’] = timestamp

Sign the request

payload = ‘&’.join([f’{param}={value}’ for param, value in params.items()])
signature = base64.b64encode(private_key.sign(payload.encode(‘ASCII’)))
params[‘signature’] = signature

Send the request

headers = {
response = requests.get(’,

Hi there,

You can take a look at the signature-examples Github repo and use the example code as a reference point.

You can generate a key pair using the Asymmetric Key Generator program. You would then save the private key and keep that to yourself and copy the public key to paste in the new API creation area on In your code, you would load the contents of the private key .pem file as so:

with open(PRIVATE_KEY_PATH, 'rb') as f:
    private_key = load_pem_private_key(,

Hi! Thank you for the reply. I made my test exactly by but the problem may be 1) I don’t know how to create pem file 2) My keys are Hmac. Are they suitable for this example of code ? ( with base64 module)

Oh so you are using the standard API key/secret pair then? Plaintext API key + plaintext Secret key generated directly on the website? If so, then it’s a different process. The process outlined above is only if you’re using ED25519/RSA Keys where you generate the keys locally, only share your public key with Binance and in return are provided with an API key. You should be following this example if that’s the case: