Ethereum: Binance with Python requests but works with curl

Ethereum Order Placement Issue: Binance API Key Forms

As a development carrhing with cryptocurrence markets, Hower, when it comes to Binance’s api, a specified issue that can-cause unexpected behavior in your python code.

The problem is binance of api uss api format for api keys the requirement library type in the subports. Specifically, Binance Requires an api-key' parameter in the URL, butch shueld ben doubin in the double () to expected input format.

In this article,

Whoapo-keyissue?

When Binance's api, however, expercts anapi-keyparameter in plain text (without quotes). The this inconsistency can be issues whon trying to authenticate with api.

The Problem: Binance Testne API

The Binance Supports both tests and in the apiis, but you can get totnet aipo is affected by this. . Iif you're still experience with a test api, we'll focuus is not in the potential solutions.

Workaround 1: Using Binance's API Wrapper

One Solution to this problem is to be a binary api wrapper for python. This

python

import json

From Binance.Client Import Client

Ethereum: Binance <Api-key format invalid.> with Python requests but works with curl<br />

Replace with your actual api key

Api_key = "your_api_key_here"

Api_secret = "your_appi_secret_here"

clien = clien (api_key = api_key, api_secret = api_secret)

Def Place_ORDER (Symbol, Side, Quantity, Price):

order = {

"Symbol": Symbol,

"Page": Page,

"Type": "Limit",

"Quantity": Quantity,

"Price": Float (Price)

}

result = clinical

Print (Json.dumps (Result, Indent = 4))

Place_ORDER ("Ethusdt," "Buy," 10, 0.1)

API KEY AND SECRET, THAT DEFINE A Place_ORDER FUNCTION Function them the binance.

Wort 2: Using Curl With An Environment Varable

Anonther Solution is to dose curl with an environment variable containing your api key.

bash

export binance_key = “your_apopi_key_here”

-X Post \ Curl

\

-O

-DATA-URENCODE “SIDE = BUY” \

-DATA-URENCODE “Type = Limit” \

-DATA-URENCODE “Quantity = 10” \

-DATA-URENCODE “PRICE = 0.1”

`

In the instant Example, Welfare an Environment Vare binance_keya with your actual api ky and secret. They,

Conclusion

The issue you're experience is not unique to Ethereum or Binance's APIS; It’s affects of several all-cryptocurrency platforms as well. Outlined above.

  • Forrequests’ and other python libraries: the use the binance of api wrapper library.

.

By

Fiat Currency Cosmos