Я сталкиваюсь с проблемой соединения neo4j при попытке запустить код neo4j;То же самое работает нормально за пределами докера, но не может установить соединение с базой данных neo4j во время работы внутри докера.
Сообщение об ошибке:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 835, in _connect
s.connect(resolved_address)
OSError: [Errno 99] Cannot assign requested address
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 3, in <module>
driver = GraphDatabase.driver(uri, auth=("neo4j", "admin"))
File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 116, in driver
return Driver(uri, **config)
File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 157, in __new__
return subclass(uri, **config)
File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 231, in __new__
pool.release(pool.acquire())
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 719, in acquire
return self.acquire_direct(self.address)
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 612, in acquire_direct
connection = self.connector(address, error_handler=self.connection_error_handler)
File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 228, in connector
return connect(address, **dict(config, **kwargs))
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 976, in connect
raise last_error
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 966, in connect
s = _connect(resolved_address, **config)
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 847, in _connect
raise ServiceUnavailable("Failed to establish connection to {!r} (reason {})".format(resolved_address, error))
neobolt.exceptions.ServiceUnavailable: Failed to establish connection to ('::1', 11010, 0, 0) (reason [Errno 99] Cannot assign requested address)
Я использовал следующий код:
from neo4j import GraphDatabase
uri = "bolt://localhost:11010/"
driver = GraphDatabase.driver(uri, auth=("neo4j", "admin"))
with driver.session() as session:
result = session.run("MATCH (n) RETURN count(n)")
print(result)
session.close()
Мой порт для болта - 11010, как в коде.Я что-то здесь упускаю?Я попробовал следующие вещи, но не повезло
1) использовал 127.0.0.1 вместо localhost
2) закрыл сессии
И мой файл докера выглядит следующим образом:
FROM python:3
ADD test.py /
RUN pip install pandas
RUN pip install pymysql
RUN pip install sqlalchemy
RUN pip install neo4j
CMD ["python","test.py"]