![](/img/trans.png)
[英]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.