Information about the Ethereum account on the capacity on binance with python-binance
As a cryptocurrency enthusiast, you can know the importance of regular monitoring of account information. One convenient way to achieve this is to connect to the API Binance interface and get information about the account using the Python-Binance library. However, I encountered a problem in which the script does not get the expected information about the account.
problem:
Trying to connect with API Binance with the Python-Binance version at 0.7.9, I met with the “attributeeerror:” nonetyp “object has no attribute coding”. This error message suggests that the library is waiting for an object with a special attribute called “Encode”, but instead receives no.
Solution:
After some studies and debugging, I identified the main reason for this problem:
* The format of the API request: The format of the API Binance request has changed since the last issue. In particular, the Python-Binance method used for “Conct_get” requires an additional parameter to determine the API parameter. In the old version (0.5.x) you do not have to provide any parameter to get account information. However, in the latest version (0.7.X) and later this parameter is required.
Here is a review of the script, which should work with the Python-Binance version 0.7.9:
`Python
import
Import json
Def get_account_details ():
List the API
Api_key = "your_api_key"
Replace with your secret key (if you are asked to generate it)
Api_secret = "your_api_secret"
Set API parameters and parameters
Endpoint = " conct_get"
Paramate = {{
"Apikey": API_KEY,
"Secret": API_secret,
"Lang": "en_us",
Add the desired version of the API (e.g. 2, 3 etc.)
"V": "1" if os.environ.get ("binance_api_version") == '1' else "2"
}
to try:
Make a request of the API
Answer = Request.Post (destination, params = params)
Pars Json answer
Data = json.lylads (answer.text)
Write information about the account and return it
If data ["data"]:
result = {
"Conct_id": Data ["Data"] ["ID"],
"Conct_balance": float (Data ["Data" ["Balance"]),
"Conct_address": Data ["Data"] ["Address"]
}
Print (json.dumps (result, contribution = 4))
Other:
Print ("no information about the account.")
Except for demands. Exception.requestexception as E:
Print (f "error: {e}")
Run the function to get information about the account
Get_account_details ()
Note:
This script will use the default version of the API (in this case 1), unless you set the “binance_api_version” environmental variable. Replace “own_api_key” and “own_api_secret” for actual accreditation data API Binance.
When making these changes, the code should now successfully recover the Ethereum account using Python-Binance without contacting the object “Attributeeerror:” Nonetipe “without attributes.