Ethereum Python Library Issues with Binance Account Login

As a developer, I always get annoyed when my favorite libraries don’t work as expected. We recently encountered an issue with the get_account() function of the etherscan.io library on Binance, which causes errors when trying to log in to the exchange.

Issue:

Ethereum: python: Binance error of using get_account()

When using the get_account() function from the etherscan.io library, it attempts to get a user account object. However, this object is a coroutine, which means its internal state is not yet initialized when it is called. This leads to the following errors:

  • TypeError: Object 'coroutine' cannot be signed: The string info['balances'] attempts to access the coroutine’s balances property, which makes no sense.
  • RuntimeWarning: The coroutine 'get_account' is used before it is defined

Solutions:

To solve this issue, you can use one of the following approaches:

Approach 1: Use the login() function of the etherscan.io library

The etherscan.io library provides an easier way to log in to the exchange without having to worry about coroutines.

from etherscan import get_account

login_to_binance() definition:

user = wait get_account('0xYourUserName')

return user






Usage:

user = login_to_binance()

Approach 2: Using a non-coroutine implementation of get_account()

If you need to use the get_account() function from the etherscan.io library, you can create a non-cryptographic implementation that returns an object instead of a coroutine.

from etherscan import get_account

class BinanceAccount:

def __init__(self, user_id):

self.user = get_account(user_id)

definition login_to_binance():

account = BinanceAccount('0xYourUserName')

return account.user


Usage:

account = login_to_binance()

Approach 3: Using a third-party library with a coroutine-free implementation

If you still can’t solve the problem, consider using a third-party library like py-scan, which has a non-cryptographic implementation of the get_account() function.

import py_scanner

login_to_binance() definition:

user = py_scanner.get_user('0xYourUserName')

return user


Usage:

user = login_to_binance()

Conclusion:

Finally, it should be noted that using the get_account() function of the etherscan.io library on Binance can be difficult due to its coroutine nature. By following these approaches or using a third-party library with a non-cryptographic implementation, you can solve this problem and continue developing Ethereum applications.

Commit message:

Added a workaround to log in to your Binance account using thelogin_to_binance()function

API Documentation:

  • get_account(user_id): Retrieves an account object from the Ethereum network.
  • login_to_binance(): Logs into the Binance exchange and returns a user object.
  • BinanceAccount(…): A non-cryptographic implementation of theget_account()` function that returns an object instead of a coroutine.

internet bybit