简体   繁体   English

在Docker中连接neo4j时出现py2neo AddressError

[英]py2neo AddressError When Connecting to neo4j in Docker

I am having difficulty creating a Graph object on Neo4j 3.4.6 using py2neo 4.10 with Python 3.7.0. 我在使用Python 2.7.0和py2neo 4.10在Neo4j 3.4.6上创建Graph对象时遇到困难。

I created a Docker container running Neo4j, and I disabled authentication using Dockerfile entry ENV NEO4J_AUTH=none . 我创建了一个运行Neo4j的Docker容器,并使用Dockerfile条目ENV NEO4J_AUTH=none禁用了身份验证。 I verified that I can browse to the Neo4j database from the host with http://localhost:7474 and that I was not required to enter a password. 我确认可以使用http:// localhost:7474从主机浏览到Neo4j数据库,并且不需要输入密码。

I created a second Docker contain for my web server. 我为我的Web服务器创建了第二个Docker容器。 I accessed the Bash shell using Docker exec -it 033f92b042c1 /bin/bash . 我使用Docker exec -it 033f92b042c1 /bin/bash访问了Bash shell。 I verified that I can ping the Docker image containing the Neo4j installation. 我确认可以对包含Neo4j安装的Docker映像执行ping操作。

From the second Docker image, I tried to create a Database object or a Graph object. 从第二个Docker映像中,我尝试创建一个Database对象或Graph对象。

import neo4j
import py2neo
from py2neo import Graph
graph = Graph("bolt://172.17.0.3:7687")

I tried different protocols and localhost rather than the IP. 我尝试了不同的协议和localhost而不是IP。 In each case, Python throws this: 在每种情况下,Python都会抛出以下内容:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/py2neo/database.py", line 88, in __new__
    inst = cls._instances[key]
KeyError: '5280a6d494b601f0256493eab3a08e55'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/py2neo/database.py", line 305, in __new__
    database = Database(uri, **settings)
  File "/usr/local/lib/python3.7/site-packages/py2neo/database.py", line 92, in __new__
    from py2neo.internal.http import HTTPDriver, HTTPSDriver
  File "/usr/local/lib/python3.7/site-packages/py2neo/internal/http.py", line 26, in <module>
    from neo4j.addressing import SocketAddress
  File "/usr/local/lib/python3.7/site-packages/neo4j/addressing.py", line 26, in <module>
    from neo4j.exceptions import AddressError
ImportError: cannot import name 'AddressError' from 'neo4j.exceptions' (/usr/local/lib/python3.7/site-packages/neo4j/exceptions.py)

Am I missing a dependency, or is there another way I should be connecting the Docker images? 我是否缺少依赖关系,或者还有另一种方式应该连接Docker映像?

Py2neo doesn't require neo4j. Py2neo不需要neo4j。 It is possible that the reason is neo4j is creating problem. 原因可能是neo4j正在产生问题。 In my case,be sure to make clean installation, I removed all neo4j-related modules and then install py2neo with its requirement neo4j-driver. 就我而言,请确保干净安装,我删除了所有与neo4j相关的模块,然后安装py2neo及其要求的neo4j-driver。

pip uninstall neo4j neobolt neo4restclient neo4j-driver py2neo

then install: 然后安装:
pip install neo4j-driver py2neo

I hope that will work. 我希望这会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM