[英]Django + Postgres: A string literal cannot contain NUL (0x00) characters
[英]Django + Postgres: saving PDF file with NUL (0x00) characters to DB and decoding it back to PDF
我有一个 pdf 文件要保存在我的 Postgres 数据库中
当我尝试保存文件时,它带来了A string literal cannot contain NUL (0x00) characters.
所以我遵循了here的解决方案,用 字符替换了 null
unicode(ppbData[0], errors='ignore').replace("\\x00", "\�")
问题是我现在无法将其转换回 PDF。 我试过encode()
和其他方法
file = open('new.pdf', 'wb')
file.write(text.encode())
file.close()
但它返回空白的pdf
有什么方法可以用 null 替换 字符或以任何其他方式将其转换回普通 pdf? 也许替换的第一个解决方案也不正确,还有另一种方法吗?
我有一个 pdf 文件要保存在我的 Postgres 数据库中
当我尝试保存文件时,它带来了A string literal cannot contain NUL (0x00) characters.
所以我遵循了here的解决方案,用 字符替换了 null
unicode(ppbData[0], errors='ignore').replace("\\x00", "\�")
问题是我现在无法将其转换回 PDF。 我试过encode()
和其他方法
file = open('new.pdf', 'wb')
file.write(text.encode())
file.close()
但它返回空白的pdf
有什么方法可以用 null 替换 字符或以任何其他方式将其转换回普通 pdf? 也许替换的第一个解决方案也不正确,还有另一种方法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.