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

msgpack-python 1.0 compatibility #5

Open
teake opened this issue Mar 3, 2020 · 2 comments
Open

msgpack-python 1.0 compatibility #5

teake opened this issue Mar 3, 2020 · 2 comments

Comments

@teake
Copy link

teake commented Mar 3, 2020

It seems loads in msgpack-python 1.0 now returns a string (it was bytes previously), so doing

return loads(response.content)

and then a decode() in

return _asciigraph.graph_to_ascii(graph, timeout=timeout).decode(encoding='UTF-8')

results in an error.

@noragen
Copy link

noragen commented Apr 14, 2020

The solution would be something like:

 pyasciinet/asciinet/__init__.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pyasciinet/asciinet/__init__.py b/pyasciinet/asciinet/__init__.py
index 1a81b84..e9c3659 100644
--- a/pyasciinet/asciinet/__init__.py
+++ b/pyasciinet/asciinet/__init__.py
@@ -104,5 +104,8 @@ def _cleanup():
 def graph_to_ascii(graph, timeout=10):
     if not isinstance(graph, nx.Graph):
         raise ValueError('graph must be a networkx.Graph')
-
-    return _asciigraph.graph_to_ascii(graph, timeout=timeout).decode(encoding='UTF-8')
+    
+    try:
+        return _asciigraph.graph_to_ascii(graph, timeout=timeout).decode(encoding='UTF-8')
+    except:
+        return _asciigraph.graph_to_ascii(graph, timeout=timeout)

@ricosaurus
Copy link

ricosaurus commented Apr 21, 2021

Thanks for the fix. Just found and installed asciinet. Have been looking for exactly this (networkx to ascii graphs) for ages! Hope it gets some love.

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