Forums

Cannot import authenticate from py2neo

Hello

I am pretty new to both python and pythonanywhere so possibly I am missing something obvious. I am trying to set up a connection to a GrapheneDB neo4j instance using the py2neo driver.

I have:

  • created a virtual environment (following the pythonanywhere instructions)
  • activated the new environement with 'workon venv;
  • run pip install py2neo
  • followed the instructions at https://docs.graphenedb.com/docs/python#section-py2neo-v3 (substituting my server and user name details)

When I reload the app I get the following in the error log:

2018-07-18 12:54:44,499: Error running WSGI application
2018-07-18 12:54:44,502: ImportError: cannot import name 'authenticate'
2018-07-18 12:54:44,502:   File "/var/www/jirosmunro_pythonanywhere_com_wsgi.py", line 18, in <module>
2018-07-18 12:54:44,503:     from flask_app import app as application  # noqa
2018-07-18 12:54:44,503: 
2018-07-18 12:54:44,503:   File "/home/JirosMunro/squares/flask_app.py", line 6, in <module>
2018-07-18 12:54:44,503:     from py2neo import authenticate, Graph, Node, Relationship
2018-07-18 12:54:44,503: ***************************************************
2018-07-18 12:54:44,503: If you're seeing an import error and don't know why,
2018-07-18 12:54:44,503: we have a dedicated help page to help you debug: 
2018-07-18 12:54:44,503: https://help.pythonanywhere.com/pages/DebuggingImportError/
2018-07-18 12:54:44,503: ***************************************************

I cannot find much on Google other than the same instructions about importing authenticate so was hoping someone may be able to point me in the right direction.

Many thanks

I tried a different construct:

from py2neo import Graph

url="bolt://hobby-mysite.dbs.graphenedb.com:24786"
user="username"
pwd="password"

graph = Graph(url, auth=(user, pwd),bolt=True, secure=True, http_port = 24789, https_port = 24780)

Now I don't get any import errors but I do get a service unavailable so trying to find out more about that error at the moment.

neo4j.exceptions.ServiceUnavailable: Failed to establish connection to ('34.244.149.253', 24786) (reason 111)

Looks like the error refused was because I was on a free account. Once I upgraded to a Hacker account everything then worked fine.

That would make sense -- I don't know exactly which protocol neo4j uses, but I'd guess it's not HTTP or HTTPS, and free accounts can only make HTTP(S) requests to sites on our whitelist.

Regarding the import error -- had you specified that your website should use it? There's a place to specify the virtualenv on the "Web" page.

Hi Giles

The protocol is Bolt on a strange port so that would fit. And I had set the venv path on the 'Web' page of my account and everything was working happily before I tried the import. I noticed that the documentation that GrapheneDB have on their site refers to py2neo v3 and the version I was using was v4. Possibly not related but as soon as I tried the new construct and upgraded the account everything is working happily! Thanks.