Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'bytes' is not JSON serializable bug #30

Open
adrastee opened this issue Mar 12, 2021 · 3 comments
Open

'bytes' is not JSON serializable bug #30

adrastee opened this issue Mar 12, 2021 · 3 comments

Comments

@adrastee
Copy link

Using python3 - i know its experimental,

Traceback (most recent call last):
File "/home/a/pywallet/pywallet.py", line 3936, in
wallet = json.dumps(json_db, sort_keys=True, indent=4)
File "/usr/lib/python3.6/json/init.py", line 238, in dumps
**kw).encode(obj)
File "/usr/lib/python3.6/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/lib/python3.6/json/encoder.py", line 430, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.6/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/usr/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.6/json/encoder.py", line 437, in _iterencode
o = _default(o)
File "/usr/lib/python3.6/json/encoder.py", line 180, in default
o.class.name)
TypeError: Object of type 'bytes' is not JSON serializable

Any chance it can be debugged?
Thanks!

@alcalawil
Copy link

same issue

@alcalawil
Copy link

I add this function to the end of the file

def dump_wallet(path_to_wallet):
	dumpbalance = False
	wallet_dir, wallet_name = os.path.split(path_to_wallet)

	db_env = create_env(wallet_dir)

	read_wallet(json_db, db_env, wallet_name, True, True, "", not(dumpbalance is None))
	wallet = json.dumps(json_db, sort_keys=True, indent=4)
	return wallet

and also modified the balance function to support python3

def balance(site, address):
	page = ""
	try:
		page=urllib.urlopen("%s%s" % (site, address))
	except:
		import urllib.request
		print('Python3 error: urllib.urlopen is not supported. Trying urllib.request.urlopen')
		page=urllib.request.urlopen("%s%s" % (site, address))
	return page.read()

and works

@wnayes
Copy link

wnayes commented May 16, 2021

I got past the 'bytes is not JSON serializable error by installing simplejson.

pip install simplejson

This works because the script first tries to load simplejson, and then falls back to the built-in json, and apparently that fallback is not python 3 compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants