From 2ba42ba145c9a31f13303de075473a48a502e16a Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 11 Sep 2019 16:50:09 -0500 Subject: [PATCH] fixed bytes encoding on getdata endpoint --- onionr/communicatorutils/downloadblocks/__init__.py | 1 + onionr/httpapi/miscpublicapi/getblocks.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/onionr/communicatorutils/downloadblocks/__init__.py b/onionr/communicatorutils/downloadblocks/__init__.py index ab289bc7..02ce564c 100755 --- a/onionr/communicatorutils/downloadblocks/__init__.py +++ b/onionr/communicatorutils/downloadblocks/__init__.py @@ -64,6 +64,7 @@ def download_blocks_from_communicator(comm_inst): if not comm_inst.shutdown and peerUsed.strip() != '': logger.info("Attempting to download %s from %s..." % (blockHash[:12], peerUsed)) content = peeraction.peer_action(comm_inst, peerUsed, 'getdata/' + blockHash, max_resp_size=3000000) # block content from random peer (includes metadata) + if content != False and len(content) > 0: try: content = content.encode() diff --git a/onionr/httpapi/miscpublicapi/getblocks.py b/onionr/httpapi/miscpublicapi/getblocks.py index 28693110..a93909a1 100755 --- a/onionr/httpapi/miscpublicapi/getblocks.py +++ b/onionr/httpapi/miscpublicapi/getblocks.py @@ -47,7 +47,8 @@ def get_block_data(publicAPI, data): try: block = block.encode() # Encode in case data is binary except AttributeError: - abort(404) + if len(block) == 0: + abort(404) block = bytesconverter.str_to_bytes(block) resp = block if len(resp) == 0: