I'm using psycopg2
to save a JSON file to a PSQL database. I keep getting this error: ValueError: A string literal cannot contain NUL (0x00) characters.
How do you detect and remove a NUL
character from a string? Can't find an answer that's not in C.
Also, this is NOT a standard find/replace character question. So far as I can tell, a NUL character is not a whitespace or newline - I don't know how it's encoded in UTF-8.
Error message:
sudo python3 json_to_psql.py -f /home/data/aggressive_dedup.json -n reviews -s reviews_schema.json
/home/.local/lib/python3.6/site-packages/psycopg2/__init__.py:144:
Traceback (most recent call last):
File "json_to_psql.py", line 89, in <module>
insert_json_into_psql(args.name, columns, elements, cur)
File "json_to_psql.py", line 57, in insert_json_into_psql
execute_values(cursor, insert_query, values)
File "/home/rob/.local/lib/python3.6/site-packages/psycopg2/extras.py", line 1271, in execute_values
parts.append(cur.mogrify(template, args))
ValueError: A string literal cannot contain NUL (0x00) characters.