nicolewhite / neo4j-flask Goto Github PK
View Code? Open in Web Editor NEWFlaskr Extended with Neo4j and Py2neo.
Home Page: http://nicolewhite.github.io/neo4j-flask/
Flaskr Extended with Neo4j and Py2neo.
Home Page: http://nicolewhite.github.io/neo4j-flask/
Hi Nicole,
I am trying to do this:
port = gdb.labels.create(“Port”)
buenos_aires = gdb.nodes.create(name=”Buenos Aires”)
new_york = gdb.nodes.create(name=”New York”)
liverpool = gdb.nodes.create(name=”Liverpool”)
casablanca = gdb.nodes.create(name=”Casablana”)
cape_town = gdb.nodes.create(name=”Cape Town”)
port.add(buenos_aires, new_york, liverpool, casablanca, cape_town)
buenos_aires.relationships.create(“6 days”, new_york)
buenos_aires.relationships.create(“5 days”, casablanca)
buenos_aires.relationships.create(“4 days”, cape_town)
then how to do the query as each relationship is not the same as generic ‘LIKE’ but different number of days?
say needing to find out number of days from New York to Liverpool to Cape Town etc?
First thanks for the code and tutorial -- they are both very helpful.
Issue:
Potential Cause:
return graph.run(query, they=other.username, you=self.username).next
Fix:
Modify the return call to be:
return graph.run(query, they=other.username, you=self.username).next()
or wrap it with:
return next(graph.run(query, they=other.username, you=self.username))
Environment:
Problem
Console output
PS D:\Projects\neo4j-flask> python run.py
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\werkzeug\serving.py", line 65, in <module>
from SocketServer import ThreadingMixIn, ForkingMixIn
ModuleNotFoundError: No module named 'SocketServer'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "run.py", line 6, in <module>
app.run(host='0.0.0.0', port=port)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 828, in run
from werkzeug.serving import run_simple
File "C:\ProgramData\Anaconda3\lib\site-packages\werkzeug\serving.py", line 68, in <module>
from socketserver import ThreadingMixIn, ForkingMixIn
ImportError: cannot import name 'ForkingMixIn'
PS D:\Projects\neo4j-flask> pip install -U werkzeug
What Worked for Me
As per: https://stackoverflow.com/a/39214538/2805700
This is fixed as of Werkzeug 0.11.15. Make sure you have installed the latest version of Werkzeug. pip install -U werkzeug.
So I ran pip install -U werkzeug
Updated requirements.txt should to Werkzeug>=0.14.10
hi ma'am,
could we create search page so that we can search by using 'user' or 'tag'?I need to search blog using username and tag. Elasticsearch is not possible so that I want to make search form.
Please, Try to share some code
Thank You,
i cloned the repo and used the same code. i got the neo4j server running on localhost/7474. But when i run the app i get a 505 error saying :Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. Please help me resolve it.
(venv) antonina@antonina-HP-Pavilion-g6-Notebook-PC:~/neo4j-flask$ python run.py
Traceback (most recent call last):
File "run.py", line 1, in
from blog import app
File "/home/antonina/neo4j-flask/blog/init.py", line 1, in
from .views import app
File "/home/antonina/neo4j-flask/blog/views.py", line 1, in
from .models import User, get_todays_recent_posts
File "/home/antonina/neo4j-flask/blog/models.py", line 2, in
from passlib.hash import bcrypt
ImportError: No module named passlib.hash
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\database_init_.py", line 318, in new
inst = cls.__instances[key]
KeyError: (<class 'py2neo.database.Graph'>, <ServerAddress settings={'host': 'localhost', 'http_port': 7474}>, 'data')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\packages\httpstream\http.py", line 322, in submit
response = send()
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\packages\httpstream\http.py", line 317, in send
http.request(xstr(method), xstr(uri.absolute_path_reference), body, headers)
File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
self.send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1026, in send_output
self.send(msg)
File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 964, in send
self.connect()
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\packages\httpstream\http.py", line 80, in connect
self.source_address)
File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 724, in create_connection
raise err
File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevd.py", line 1664, in
main()
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/abc/PycharmProjects/FlaskWithNeo4j/run.py", line 1, in
from blog import app
File "C:\Users\abc\PycharmProjects\FlaskWithNeo4j\blog_init.py", line 1, in
from .views import app
File "C:\Users\abc\PycharmProjects\FlaskWithNeo4j\blog\views.py", line 1, in
from .models import User, get_todays_recent_posts
File "C:\Users\abc\PycharmProjects\FlaskWithNeo4j\blog\models.py", line 11, in
graph = Graph(url + '/db/data/')
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\database_init.py", line 327, in new
use_bolt = version_tuple(inst.remote.get().content["neo4j_version"]) >= (3,)
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\database\http.py", line 154, in get
response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\packages\httpstream\http.py", line 966, in get
return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\packages\httpstream\http.py", line 943, in __get_or_head
return rq.submit(redirect_limit=redirect_limit, **kwargs)
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\packages\httpstream\http.py", line 433, in submit
http, rs = submit(self.method, uri, self.body, self.headers)
File "C:\Users\abc\venv\untitled2\lib\site-packages\py2neo\packages\httpstream\http.py", line 362, in submit
raise SocketError(code, description, host_port=uri.host_port)
py2neo.packages.httpstream.http.SocketError: Unknown error
is uuid4 actually unique when we are dealing with ten thousands of nodes?
(venv) antonina@antonina-HP-Pavilion-g6-Notebook-PC:~/neo4j-flask$ pip install -r requirements.txt
Collecting adium-theme-ubuntu==0.3.4 (from -r requirements.txt (line 1))
Could not find a version that satisfies the requirement adium-theme-ubuntu==0.3.4 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for adium-theme-ubuntu==0.3.4 (from -r requirements.txt (line 1))
I'm trying to run it for the second time and i have constraint exception:
~/Desktop/flasktest/nicolewhite-neo4j-flask-27476c5$ python run.py
Traceback (most recent call last):
File "run.py", line 1, in
from blog import app
File "/home/antonina/Desktop/flasktest/nicolewhite-neo4j-flask-27476c5/blog/init.py", line 4, in
graph.schema.create_uniqueness_constraint("User", "username")
File "/usr/local/lib/python2.7/dist-packages/py2neo/database/init.py", line 775, in create_uniqueness_constraint
{"property_keys": [property_key]})
File "/usr/local/lib/python2.7/dist-packages/py2neo/database/http.py", line 212, in post
raise_from(GraphError(message, **content), error)
File "/usr/local/lib/python2.7/dist-packages/py2neo/util.py", line 122, in raise_from
raise exception
py2neo.database.status.ConstraintViolationException: Constraint already exists: CONSTRAINT ON ( user:User ) ASSERT user.username IS UNIQUE
How it can be solved?
Hi,
I am new to pycharm. I am using py2neo.
When I am using termial(inside pycharm), the code is working fine.
But when I use run(Alt+shift+f10), it is giving me import error.
I am not using virtualenv.
Thanks.
Hey Nicole,
I am trying to follow this code and I keep getting "ImportError: No module named py2neo", However, it works fine on python console in Pycharm.
Do you have any idea why this happen? I am using python3.5
Thanks
Hi
I am new to py2neo too, I have download and made changes suggested here to neo4j-flask blog code tutorial on my anaconda enviroment. I am having this error when trying to register user.
ValueError: Node (:U {}) does not belong to this graph
Hi,
when testing the app in the browser (i did not follow the deploy to heroku step) i get this error message:
py2neo.error.Unauthorized
py2neo.error.Unauthorized: http://localhost:7474/db/data/
and a traceback list:
Traceback (most recent call last):
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Niels\Anaconda3\lib\site-packages\flask\app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Niels\Documents\Visual Studio 2015\Projects\neo4j_an_d3\neo4j_and_flask\neo4j_and_flask\blog\views.py", line 9, in index
posts = get_todays_recent_posts()
File "C:\Users\Niels\Documents\Visual Studio 2015\Projects\neo4j_an_d3\neo4j_and_flask\neo4j_and_flask\blog\models.py", line 41, in get_todays_recent_posts
posts = graph.cypher.execute(query, today = date())
File "C:\Users\Niels\Anaconda3\lib\site-packages\py2neo\core.py", line 667, in cypher
metadata = self.resource.metadata
File "C:\Users\Niels\Anaconda3\lib\site-packages\py2neo\core.py", line 213, in metadata
self.get()
File "C:\Users\Niels\Anaconda3\lib\site-packages\py2neo\core.py", line 261, in get
raise Unauthorized(self.uri.string)
py2neo.error.Unauthorized: http://localhost:7474/db/data/
I also testet the login credentials as described in the py2neo essentials
$ neoauth neo4j my-p4ssword
Password change not required
It would be nice if you could help me out with this.
Btw. thanks for the great tutorial!
Thanks for the great tutorial. Starting it up, two of us here both experienced problems with uniqueness constraint conflicts. We were eventually able to work around this by commenting out the uniqueness constraint check, but we don't know what the proper fix is.
This occurred even on a freshly deleted (and created) database.
In my case, the flask server was running in debug mode and neo4j was running on special localhost ports.
Here is the stack trace:
Traceback (most recent call last):
File "/home/dad/jason_work/nicole/venv_nicole/lib/python3.5/site-packages/py2neo/database/http.py", line 203, in post
response = self.__base.post(body, headers, **kwargs)
File "/home/dad/jason_work/nicole/venv_nicole/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 984, in post
return rq.submit(**kwargs)
File "/home/dad/jason_work/nicole/venv_nicole/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 452, in submit
return Response.wrap(http, uri, self, rs, **response_kwargs)
File "/home/dad/jason_work/nicole/venv_nicole/lib/python3.5/site-packages/py2neo/packages/httpstream/http.py", line 489, in wrap
raise inst
py2neo.packages.httpstream.http.ClientError: 409 Conflict
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "run.py", line 1, in <module>
from blog import app
File "/home/dad/jason_work/nicole/blog/__init__.py", line 4, in <module>
graph.schema.create_uniqueness_constraint("User", "username")
File "/home/dad/jason_work/nicole/venv_nicole/lib/python3.5/site-packages/py2neo/database/__init__.py", line 775, in create_uniqueness_constraint
{"property_keys": [property_key]})
File "/home/dad/jason_work/nicole/venv_nicole/lib/python3.5/site-packages/py2neo/database/http.py", line 212, in post
raise_from(GraphError(message, **content), error)
File "/home/dad/jason_work/nicole/venv_nicole/lib/python3.5/site-packages/py2neo/util.py", line 124, in raise_from
raise exception
py2neo.database.status.ConstraintViolationException: Constraint already exists: CONSTRAINT ON ( user:User ) ASSERT user.username IS UNIQUE
I am trying to use neo4jsandbox.com/browser/ for query.
I don't prefer to download it.
please suggest me a solution.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.