Problem with POST request to rdf/neo4j/cypher

On Neo4j v4.2.3
n10s v.
I am using the following python code to submit GET and POST requests to the rdf endpoint of my database:

import requests
import os
import json

rdf_host = "http://localhost:11006/rdf"
get_pstfx = "/neo4j/describe/13"
post_pstfx = "/neo4j/cypher"
credentials=(os.environ.get("NEO4J_USER"), os.environ.get("NEO4J_PASSWORD"))

get_url = rdf_host + get_pstfx
get_response = requests.get(get_url, auth=credentials).text
print(f"get_response: {get_response}")

post_url = rdf_host + post_pstfx
post_data = {
    "cypher": "MATCH (x) RETURN x",
    "cypherParams": {},
    "format": "Turtle"
post_response =, auth=credentials, data=post_data)
print(f"post_response: {post_response}")

post_response2 =, auth=credentials, json=json.dumps(post_data))
print(f"post_response2: {post_response2}")

I get the following results:

get_response: @prefix n4sch: <neo4j://graph.schema#> .
@prefix n4ind: <neo4j://graph.individuals#> .

<neo4j://graph.schema#Car#toyota#petrol> a n4sch:Car;
  n4sch:fuel "petrol";
  n4sch:model "toyota" .

post_response: <Response [500]>
post_response2: <Response [500]>

so GET requests work fine, however neither of the POST requests worked (I tried with passing python object into data= and passing json serialization into json=)
They fail with 500 Internal Server Error, which makes me think the problem with with the contents of data I submit in the POST request...

Interesting fact that when I submit

:POST /rdf/neo4j/cypher {"cypher": "MATCH (x) RETURN x", "format": "Turtle"}

in MS Edge browser, the query works:

when I submit the query in Neo4j Desktop Browser, it does not:

Could you please help me with that?
What I am trying to achieve is the real Turtle serialization of a custom cypher query result. As far as I understood there is no such n10s.* procedure to do that (n10s.rdf.export.cypher returns a table of triples)

Thank you!

Hi @paltusplintus,

You were nearly there :) Pasing the python dictionary into the json param does the job. No need to do json serialization. This is the fragment I've tested:

post_url = rdf_host + post_pstfx
post_data = {
    "cypher": "MATCH (x) RETURN x limit 3",
    "cypherParams": {},
    "format": "Turtle"
post_response =, auth=credentials, json=post_data)
print(f"post_response: {post_response.content}")

The n10s.export.* (cypher and spo) procedures are useful when you want to decouple the HTTP endpoint from the DB. In that case the a client will communicate with the DB+n10s using the python driver, and take care of serialising the triples-as-records.

You may find this thread useful.

Finally, on the behavior of the browsers I really cannot explain. For the HTTP requests, I'd suggest (that's what I normally do) to test using curl or some rest client like postman or rested.
I see no issues on chrome at my end but let me know if the problem persists and you think it's worth me trying to reproduce it. I'd need more details like versions of db+n10s+browser... etc.

Hope this helps.



1 Like