我正在使用psycopg2
将JSON文件保存到PSQL数据库。我一直收到此错误:ValueError: A string literal cannot contain NUL (0x00) characters.
如何从字符串中检测并删除NUL
字符?无法找到不在C中的答案。
此外,这不是标准的查找/替换字符问题。据我所知,NUL字符不是空格或换行符 - 我不知道它是如何用UTF-8编码的。
错误讯息:
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.