Skip to content
Snippets Groups Projects
Commit 5aad2059 authored by Vincent Texier's avatar Vincent Texier
Browse files

[fix] #140 fix errors after merge resolve conflicts

parent c593c349
No related branches found
No related tags found
1 merge request!125Mnemonic dewif
Pipeline #11341 passed
......@@ -260,7 +260,7 @@ class API:
response = request.urlopen(duniter_request, timeout=15) # type: HTTPResponse
if response.status != 200:
content = str(response.read())
content = response.read().decode("utf-8")
if bma_errors:
try:
error_data = parse_error(content)
......@@ -276,7 +276,7 @@ class API:
# get response content
return_response = copy.copy(response)
content = str(response.read())
content = response.read().decode("utf-8")
response.close()
# if schema supplied...
......
......@@ -26,7 +26,7 @@ from itertools import groupby
from duniterpy.key import VerifyingKey
async def get_available_nodes(client: Client) -> List[List[Dict[str, Any]]]:
def get_available_nodes(client: Client) -> List[List[Dict[str, Any]]]:
"""
Get available nodes grouped and sorted by descending blockstamp
......@@ -52,8 +52,8 @@ async def get_available_nodes(client: Client) -> List[List[Dict[str, Any]]]:
:return:
"""
# capture heads and peers
heads_response = await client(bma.network.ws2p_heads)
peers_response = await client(bma.network.peers)
heads_response = client(bma.network.ws2p_heads)
peers_response = client(bma.network.peers)
# get heads instances from WS2P messages
heads = []
......
......@@ -15,8 +15,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import asyncio
from duniterpy.helpers import network
from duniterpy.api.client import Client
......@@ -26,20 +24,19 @@ from duniterpy.api.client import Client
# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
# Here we use the secure BASIC_MERKLED_API (BMAS)
BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
BMAS_ENDPOINT = "BMAS g1.duniter.org 443"
################################################
async def main():
def main():
"""
Main code
"""
# Create Client from endpoint string in Duniter format
client = Client(BMAS_ENDPOINT)
groups = await network.get_available_nodes(client)
groups = network.get_available_nodes(client)
for group in groups:
block = group[0]["head"].blockstamp
print(f"block {block} shared by {len(group)} nodes")
......@@ -50,10 +47,6 @@ async def main():
for endpoint in node["endpoints"]:
print(endpoint)
# Close client aiohttp session
await client.close()
# Latest duniter-python-api is asynchronous and you have to use asyncio, an asyncio loop and a "as" on the data.
# ( https://docs.python.org/3/library/asyncio.html )
asyncio.get_event_loop().run_until_complete(main())
if __name__ == "__main__":
main()
......@@ -21,10 +21,9 @@ import jsonschema
from jsonschema import ValidationError, SchemaError
from duniterpy.api.bma import network
from tests.api.webserver import WebFunctionalSetupMixin, web
class TestBmaNetwork(WebFunctionalSetupMixin, unittest.TestCase):
class TestBmaNetwork(unittest.TestCase):
def test_peers(self):
json_sample = {
"peers": [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment