cytoscape / py2cytoscape

Python utilities for Cytoscape and Cytoscape.js
https://py2cytoscape.readthedocs.io
MIT License
178 stars 45 forks source link

TypeError: the JSON object must be str, not 'bytes' when using py2cytoscape.cyrest.cyclient() #79

Closed yangli-ai closed 5 years ago

yangli-ai commented 5 years ago

Any operations with py2cytoscape.data.cyrest_client.CyRestClient works fine with me. But any operations with py2cytoscape import cyrest.cyclient() always returns the same error: for example, try commands: from py2cytoscape import cyrest csc=cyrest.cyclient() csc.status() # return CyREST online! csc.version() # return cytoscapeVersion 3.7.1 apiVersion v1 csc.node.list() # this command and other commands return the same error

E:\Anaconda3\lib\site-packages\py2cytoscape\cyrest\node.py in list(self, network, nodeList, verbose) 157 network=check_network(self,network,verbose=verbose) 158 PARAMS=set_param(["network", "nodeList"],[network, nodeList]) --> 159 response=api(url=self.__url+"/list", PARAMS=PARAMS, method="POST", verbose=verbose) 160 161 return response

E:\Anaconda3\lib\site-packages\py2cytoscape\cyrest\base.py in api(namespace, command, PARAMS, host, port, version, method, verbose, url) 144 print(r.content) 145 sys.stdout.flush() --> 146 res=json.loads(r.content) 147 if "errors" in res.keys(): 148 if len(res["errors"]) > 0:

E:\Anaconda3\lib\json__init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 310 if not isinstance(s, str): 311 raise TypeError('the JSON object must be str, not {!r}'.format( --> 312 s.class.name__)) 313 if s.startswith(u'\ufeff'): 314 raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",

TypeError: the JSON object must be str, not 'bytes'

zachary822 commented 5 years ago

This is a behavior of python 3.5 or earlier. Starting python 3.6 json.loads can accept byte strings. I'll see if I can make a pull request to fix it for you.

zachary822 commented 5 years ago

Even though this issue doesn't exist after python 3.6, I feel the changes in #84 should make the code a bit more clear.

yangli-ai commented 5 years ago

Thanks. That is the problem.