neo4j-graphacademy / app-python Goto Github PK
View Code? Open in Web Editor NEWhttps://graphacademy.neo4j.com/courses/app-python
https://graphacademy.neo4j.com/courses/app-python
This is not a code issue per se. But I do have a request. Hope it is OK to post in this section.
I have been going through the course and completed it more or less with the help of the issues listed here. It is a nice course. I have a much better understanding of neo4j and cypher now.
I was wondering if the source for the UI code is available for learning purposes. I am new to javascript and was hoping to use this course as a way to get a better understanding of how the UI is built and what it does.
I did see there is a UI repository for neoflix but I think it is not the same code base as this graph academy course.
Let me know.
The code in the repository on the githab and in the course module on the site is different.
Registration and authorization do not work. I admit that I might have done something wrong. Below is the terminal output.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask/app.py", line 2548, in __call__
return self.wsgi_app(environ, start_response)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask/app.py", line 2528, in wsgi_app
response = self.handle_exception(e)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/api/routes/auth.py", line 32, in login
user = dao.authenticate(email, password)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/api/dao/auth.py", line 107, in authenticate
user = session.execute_read(get_user, email=email)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/work/session.py", line 590, in execute_read
return self._run_transaction(
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/work/session.py", line 523, in _run_transaction
raise errors[-1]
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/work/session.py", line 480, in _run_transaction
self._open_transaction(
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/work/session.py", line 388, in _open_transaction
self._connect(access_mode=access_mode)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/work/session.py", line 120, in _connect
super()._connect(access_mode, **access_kwargs)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/work/workspace.py", line 168, in _connect
self._connection = self._pool.acquire(**acquire_kwargs_)
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/io/_pool.py", line 411, in acquire
return self._acquire(
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/io/_pool.py", line 221, in _acquire
return connection_creator()
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/io/_pool.py", line 138, in connection_creator
connection = self.opener(
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/io/_pool.py", line 386, in opener
return Bolt.open(
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_sync/io/_bolt.py", line 322, in open
BoltSocket.connect(
File "/home/adrian/PycharmProjects/Other/neo4j-graphacademy/app-python/neoflix/lib/python3.10/site-packages/neo4j/_async_compat/network/_bolt_socket.py", line 679, in connect
raise ServiceUnavailable(
neo4j.exceptions.ServiceUnavailable: Couldn't connect to 3.239.35.134:7687 (resolved to ()):
Failed to read any data from server ResolvedIPv4Address(('3.239.35.134', 7687)) after connected
When working on the "Project Backlog" section, specifically the "Movie Details" task, I get an error when running the solution provided in the 12-movie-details
branch. When you go to a page like http://localhost:3000/movies/9772
. An error will appear in the flask log
raceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/workspaces/neo-py-tutorial/api/routes/movies.py", line 42, in get_movie_details
return jsonify(movie)
File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 355, in jsonify
f"{dumps(data, indent=indent, separators=separators)}\n",
File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 133, in dumps
rv = _json.dumps(obj, **kwargs)
File "/usr/local/lib/python3.9/json/__init__.py", line 234, in dumps
return cls(
File "/usr/local/lib/python3.9/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/local/lib/python3.9/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/local/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/local/lib/python3.9/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/usr/local/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/local/lib/python3.9/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 57, in default
return super().default(o)
File "/usr/local/lib/python3.9/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Date is not JSON serializable
The ultimate error "TypeError: Object of type Date is not JSON serializable" seems to be coming from the "born" property of the Actor nodes which are returned to python as objects like neo4j.time.Date(1986, 10, 14)
and those are not properly serialized by the flask.jsonify
function. The full cypher query used for that task is
MATCH (m:Movie {tmdbId: $id})
RETURN m {
.*,
actors: [ (a)-[r:ACTED_IN]->(m) | a { .*, role: r.role } ],
directors: [ (d)-[:DIRECTED]->(m) | d { .* } ],
genres: [ (m)-[:IN_GENRE]->(g) | g { .name }],
favorite: m.tmdbId IN $favorites
} AS movie
LIMIT 1
Is there a recommended work around? Does the code in api/routes/movies.py need to change to so as to not use jsonify
? Or is there an easy way to convert those neo4j.time.Date
objects into strings in the cypher query itself?
This occurs running Python 3.9.12 with Flask 2.0.2 and neo4j 4.4.0 using the sample Recommendations graph database.
Hi
I am a newbie to this world so would really appreciate any help.
I get an error when running flask run
Is there supposed to be an api.py file?
The error i get is
(sandbox) PS C:\Users\cv\Downloads\app-python-main> flask run
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Thanks
In number of methods in the code current_user is fetched like this:
user_id = current_user["sub"] if current_user != None else None
If a user is logged this fails with error:
line 96, in get_current_user raise RuntimeError( RuntimeError: You must provide a
@jwt.user_lookup_loadercallback to use this method
My solution is to add the callback method in api/__init__.py
right after JWTManager is initialized like this:
jwt = JWTManager(app)
@jwt.user_lookup_loader
def user_lookup_callback(_jwt_header, jwt_data):
return jwt_data
I am using python==3.11, Flask==2.2.2, Flask-JWT-Extended==4.4.4 as per requirements.txt.
code
from neo4j import GraphDatabase
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
driver = GraphDatabase.driver("neo4j://localhost:7687", auth=("neo4j", "neo"))
driver.verify_connectivity()
error
opt/anaconda3/lib/python3.6/site-packages/neo4j/__init__.py", line 461, in _verify_routing_connectivity
raise ServiceUnavailable("Could not connect to any routing servers.")
neo4j.exceptions.ServiceUnavailable: Could not connect to any routing servers.
The test for the Python Applications course https://graphacademy.neo4j.com/courses/app-python/2-interacting/5-registering/ will fail on this script for reasons outside the scope of the lesson. The root cause is the _generate_token()
method.
def _generate_token(self, payload):
iat = datetime.utcnow()
payload["sub"] = payload["userId"]
payload["iat"] = iat
payload["nbf"] = iat
payload["exp"] = iat + current_app.config.get('JWT_EXPIRATION_DELTA')
return jwt.encode(
payload,
self.jwt_secret,
algorithm='HS256'
).decode('ascii')
The .decode('ascii')
should be removed in the Main branch that users initially clone.
I have followed the python API course, but I am unable to see anything on http://localhost:3000/ I am using Gitpod
The front-end data cannot be imported, the specific things in the Neo4j database are not displayed, and the registration cannot be performed.
For example "Person" module, F12 debugging shows "Failed to load resource: net::ERR_CONNECTION_REFUSED localhost:3000/api/people?limit=4:1 ", the front-end URL is "http://127.0.0.1:5000/people" ,, I don't know why.
When I try to update APP_PORT in .env to 3000 , it will report an error and cannot do this. Is it caused by regional network problems, or is it caused by no modification in some places?
I've been trying to pass the test case for Challenge: Unique email addresses, but the test case is failing:
To complete the task, one should insert the constraints in the Neo4j sandbox but running the constraint in the sandbox is giving me the below error. Before applying this constraint there are a few nodes, which already share the same email address, as result the constraint is failing.
I'm going through the python tutorial and when I get to the lesson Browsing Genre, and run the test, I get the following error messsage:
============================================================ test session starts ============================================================
platform linux -- Python 3.11.6, pytest-7.1.3, pluggy-1.0.0
rootdir: /workspace/app-python
collected 1 item
tests/09_genre_list__test.py F
================================================================= FAILURES ==================================================================
________________________________________________________ test_return_list_of_genres _________________________________________________________
app = <Flask 'api'>
def test_return_list_of_genres(app):
with app.app_context():
# Get Neo4j Driver
driver = get_driver()
# Create DAO
dao = GenreDAO(driver)
# Get all genres
> output = dao.all()
tests/09_genre_list__test.py:15:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
api/dao/genres.py:53: in all
return session.execute_read(get_movies)
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/work/session.py:660: in execute_read
return self._run_transaction(
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/work/session.py:551: in _run_transaction
result = transaction_function(tx, *args, **kwargs)
api/dao/genres.py:30: in get_movies
result = tx.run("""
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/work/transaction.py:169: in run
result._tx_ready_run(query, parameters)
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/work/result.py:131: in _tx_ready_run
self._run(query, parameters, None, None, None, None, None, None)
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/work/result.py:181: in _run
self._attach()
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/work/result.py:298: in _attach
self._connection.fetch_message()
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:178: in inner
func(*args, **kwargs)
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/io/_bolt.py:849: in fetch_message
res = self._process_message(tag, fields)
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/io/_bolt5.py:374: in _process_message
response.on_failure(summary_metadata or {})
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <neo4j._sync.io._common.Response object at 0x7fbdd2f69750>
metadata = {'code': 'Neo.ClientError.Statement.SyntaxError', 'message': 'A pattern expression should only be used in order to tes...4 (offset
: 468))\n" movies: size((g)<-[:IN_GENRE]-(:Movie)),"\n ^'}
def on_failure(self, metadata):
""" Called when a FAILURE message has been received.
"""
try:
self.connection.reset()
except (SessionExpired, ServiceUnavailable):
pass
handler = self.handlers.get("on_failure")
Util.callback(handler, metadata)
handler = self.handlers.get("on_summary")
Util.callback(handler)
> raise Neo4jError.hydrate(**metadata)
E neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: A pattern expression should only be used
in order to test the existence of a pattern. It can no longer be used inside the function size(), an alternative is to replace size() with COUNT {}. (line 13, column 34 (offset: 468)) E " movies: size((g)<-[:IN_GENRE]-(:Movie)),"
E ^}
../.pyenv_mirror/user/3.11.6/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:245: CypherSyntaxError
========================================================== short test summary info ==========================================================
FAILED tests/09_genre_list__test.py::test_return_list_of_genres - neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.Syn...
============================================================= 1 failed in 0.55s =============================================================
The issue persists even if I use the answer I constructed during the lesson, copy and paste the answer provided at the end of lesson, as well as if I copy the contents of the file in the api/dao/genres.py, so I don't know exactly how to solve the problem in the Cypher syntax.
Also for some reason, whenever I use
export FLASK_APP=api
export FLASK_ENV=development
flask run
To run the aplication from the GitPod instance, the application appears with no data and with none of the functionalities implemented thus far, even though it passed all the tests before this one. So I don't know what is wrong when I run the aplication from GitPod.
I hope anyone can help me with this.
Regards,
Nicholas
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.