如何将我的python代码连接到gephi?

时间:2017-12-19 09:49:12

标签: python gephi

我试图在python代码中创建一个图形,我需要它在gephi中可视化。我尝试过这样的python代码:

from gephistreamer import graph
from gephistreamer import streamer
stream = streamer.Streamer(streamer.GephiWS())
node_a = graph.Node("A",custom_property=1)
node_b = graph.Node("B")
node_b.property['custom_property']=2
stream.add_node(node_a,node_b)
edge_ab = graph.Edge(node_a,node_b,custom_property="hello")
stream.add_edge(edge_ab)

My gephi Graph streaming plugin is active as master. When I run the python code, error occurs like this:
HandshakeError                            Traceback (most recent call last)
<ipython-input-1-7856b7437ce1> in <module>()
      1 from gephistreamer import graph
      2 from gephistreamer import streamer
----> 3 stream = streamer.Streamer(streamer.GephiWS())
      4 
      5 # Create a node with a custom_property

/usr/local/lib/python2.7/dist-packages/gephistreamer/streamer.pyc in __init__(self, hostname, port, workspace)
    113         self.workspace = workspace
    114         self.websocket = self.Client(self._generate_url())
--> 115         self.websocket.connect()
    116     def _generate_url(self):
    117         return "ws://{hostname}:{port}/{workspace}?operation=updateGraph".format(hostname=self.hostname,

/usr/local/lib/python2.7/dist-packages/ws4py/client/__init__.pyc in connect(self)
    235 
    236         try:
--> 237             self.process_response_line(response_line)
    238             self.protocols, self.extensions = self.process_handshake_header(headers)
    239         except HandshakeError:

/usr/local/lib/python2.7/dist-packages/ws4py/client/__init__.pyc in process_response_line(self, response_line)
    300         protocol, code, status = response_line.split(b' ', 2)
    301         if code != b'101':
--> 302             raise HandshakeError("Invalid response status: %s %s" % (code, status))
    303 
    304     def process_handshake_header(self, headers):

HandshakeError:响应状态无效:404 Not Found

有人可以帮我这样做吗?

1 个答案:

答案 0 :(得分:0)

我刚刚读到您的问题也在寻找解决方案。一些提示对我的运行很有帮助:

  1. 明确指定连接:streamer.GephiWS(hostname="localhost", port=8080, workspace="workspace0")
  2. 您应该在Gephi中重命名的工作空间标题,避免使用大写字符和空格。所有大写字母都必须在python中转换为小写字母
  3. 在浏览器中测试是否可以访问http://localhost:8080/workspace0
  4. 我把插件弄乱了。。我注意到它并没有真正重新启动以影响设置。我总是关闭项目并启动新的主服务器
  5. 我将端口更改为8080