neo4j: error py2neo.database.work.ClientError [Statement.SyntaxError] Invalid input ‘W‘ expected

created at 03-18-2022 views: 17

problem

neo4j error:

error py2neo.database.work.ClientError: [Statement.SyntaxError] Invalid input ‘W’: expected ‘\’, ‘’’, ‘"’, ‘b’, ‘f’, ‘n’, ‘r’, ‘t’, UTF16 or UTF32 (line 1, column 28 (offset: 27))

error code:

MERGE (n:address {publish path:'books\2021\1\16'}) return n

reason & solution

This is because the illegal symbol \ is included

Solution

neo4j You can change it to / without affecting the usage

MERGE (n:address {publish path:'books/2021/1/16'}) return n

You can also change one \ to four: \\\\

MERGE (n:address {publish path:'books\\\\2021\\\\1\\\\16'}) return n

But this way, two \ will be displayed in neo4j, like:

publish path:'books\\2021\\1\\16'

Python

If you are operating in a programming language such as Python, you can use raw strings to solve

py2neo

a = Node('publish', publish = r'books\2021\1\16')
graph.create(a)

or

a = 'books\2021\1\16'
b = repr(a)[1:-1]
a = Node('publish', publish=b)
graph.create(a)

result:

<id>:1 publish:books\x821\021\x0e
created at:03-18-2022
edited at: 03-18-2022: