iexbase / tron-api-python

A Python API for interacting with Tron (TRX)
https://tronapi-for-python.readthedocs.io
MIT License
166 stars 84 forks source link

Python36 create account error #38

Open knight2008 opened 5 years ago

knight2008 commented 5 years ago

File "C:\Python\Python36-32\lib\site-packages\tronapi\common\account.py", line 96, in address 'base58': to_base58.decode() AttributeError: 'str' object has no attribute 'decode'

fix for python3: 'base58': to_base58

serderovsh commented 5 years ago

No problems detected

Example:

from tronapi import Tron

tron = Tron()

account = tron.create_account
is_valid = bool(tron.isAddress(account.address.hex))

logger.debug('Generated account: ')
logger.debug('- Private Key: ' + account.private_key)
logger.debug('- Public Key: ' + account.public_key)
logger.debug('- Address: ')
logger.debug('-- Base58: ' + account.address.base58)
logger.debug('-- Hex: ' + account.address.hex)
logger.debug('-- isValid: ' + str(is_valid))
logger.debug('-----------')
serderovsh commented 5 years ago

See examples https://github.com/iexbase/tron-api-python/blob/master/example.py

knight2008 commented 5 years ago

please verify the code below. Is your python version 3.x?

root@iZuf63dqaawoexrsw4tejsZ:~# python --version Python 3.7.1 root@iZuf63dqaawoexrsw4tejsZ:~# root@iZuf63dqaawoexrsw4tejsZ:~# cat tron_address.py

coding=utf-8

if name == "main": from tronapi import Tron tron = Tron() account = tron.create_account print('Generated account: ') print('- Private Key: ' + account.private_key) print('- Public Key: ' + account.public_key) print('- Address: ') print('-- Base58: ' + account.address.base58) print('-- Hex: ' + account.address.hex) print('-----------') root@iZuf63dqaawoexrsw4tejsZ:~# python tron_address.py
Generated account:

serderovsh commented 5 years ago

3.6 >

Example tronbot: https://github.com/iexbase/tron-bot/blob/b9ac20cbebf5b8b0edfd321efb7863951b528759/tron_bot.py#L242

https://t.me/iEXTronBot

Python 3.6.5 is installed on the server.

knight2008 commented 5 years ago

this line report error. print('-- Base58: ' + account.address.base58) not account = tron.create_account

Traceback (most recent call last): File "tron_address.py", line 11, in print('-- Base58: ' + account.address.base58)

diudiuwangzi commented 5 years ago

fix it.

diff -u account.py.org account.py --- account.py.org 2019-08-31 20:15:13.796771030 +0800 +++ account.py 2019-08-31 20:15:28.980771092 +0800 @@ -93,7 +93,7 @@ return AttributeDict({ 'hex': address, -- 'base58': to_base58.decode() ++ 'base58': to_base58 })

def str(self):