错误!C:\file\example.db 不是 UTF-8 编码的 ipython 笔记本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35928426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error! C:\file\example.db is not UTF-8 encoded ipython notebook
提问by jessMSUgrad
please help! I am using sqlite3 in ipython notebook to create an SQL database. I think I have successfully created the database, but when I go to look at it I am receiving an encoding UTF8 error. Here is my code:
请帮忙!我在 ipython notebook 中使用 sqlite3 创建 SQL 数据库。我想我已经成功创建了数据库,但是当我去查看它时,我收到了编码 UTF8 错误。这是我的代码:
import sqlite3
conn=sqlite3.connect('example.db')
c=conn.cursor()
c.execute('''DROP TABLE PROFILE''')
c.execute('''CREATE TABLE PROFILE
( FIRSTNAME TEXT PRIMARY KEY unique NOT NULL,
LASTNAME TEXT NOT NULL,
EMAILADDRESS TEXT NOT NULL,
PASSWORD TEXT NOT NULL,
CURRENTJOBTITLE TEXT NOT NULL,
EDUCATION TEXT NOT NULL);''')
conn.close()
conn = sqlite3.connect('example.db')
c = conn.cursor()
conn.execute("INSERT INTO PROFILE (FIRSTNAME, LASTNAME, EMAILADDRESS, PASSWORD, CURRENTJOBTITLE, EDUCATION) \
VALUES ('SALLYSUE','SUE','[email protected]','ABC', 'STUDENT', 'GRAD')");
conn.commit()
conn.close()
This is the end of my Code. When I go to look at the file created 'example.db' this is where I see the below error:
这是我的代码的结尾。当我查看创建的“example.db”文件时,我看到以下错误:
Error! C:\Users\Lastname\CSE801\example.db is not UTF-8 encoded
Saving disabled.
See Console for more details
So I am not able to see the table I am creating in SQL.
所以我看不到我在 SQL 中创建的表。
I googled this and found that people said to put this in my code
我用谷歌搜索了这个,发现人们说要把它放在我的代码中
import sys
reload(sys)
sys.setdefaultencoding()
Well once I do this and try to rerun my code the code produces nothing. It won't run the code at all. Does anyone have any suggestions? Thanks!
好吧,一旦我这样做并尝试重新运行我的代码,代码就不会产生任何结果。它根本不会运行代码。有没有人有什么建议?谢谢!
回答by user9026530
I am a complete newbie in Python and faced the similar issue. But i soon realized i was trying to access a zip folder from Jupyter and hence the error!! Unzip and access the actual file was to be done in the first place.
我是 Python 的新手,遇到了类似的问题。但我很快意识到我试图从 Jupyter 访问一个 zip 文件夹,因此出现了错误!!首先要解压缩并访问实际文件。
This may sound very basic, but it might happen to new coders.
这听起来可能很基本,但它可能会发生在新的编码人员身上。
回答by Ferro Fang
The encoding of file itself is not utf-8.
文件本身的编码不是utf-8。
You can change file character encoding by following steps in these links: http://mindspill.net/computing/linux-notes/determine-and-change-file-character-encoding/
您可以通过以下链接中的步骤更改文件字符编码:http: //mindspill.net/computing/linux-notes/determine-and-change-file-character-encoding/
Get encoding of a file in Windows
回答by user5920660
This may be a known Jupyter issue, specifically: https://github.com/jupyterhub/jupyterhub/issues/1572
这可能是一个已知的 Jupyter 问题,具体来说:https: //github.com/jupyterhub/jupyterhub/issues/1572
I experienced the same problem with ReportLab. I created a PDF file, and tried to open it from within the Jupyter web interface (on the "tree" page). I received much the same error message.
我在 ReportLab 上遇到了同样的问题。我创建了一个 PDF 文件,并尝试从 Jupyter Web 界面(在“树”页面上)打开它。我收到了大致相同的错误消息。
The first thing to do is verify outside of Jupyterthat the file was created successfully.
首先要做的是在 Jupyter 之外验证文件是否已成功创建。
The only thing I can add to the documentation on the GitHub issue is that although the output from using "view" in the URL instead of "edit" may look blank, view sourcewill show that Jupyter served a correctly-formed HTML page with a reference to the correctly-formed file, but that something is preventing the file from getting to a PDF renderer (or whatever you need for your DB file).
我可以添加到 GitHub 问题文档中的唯一一件事是,虽然在 URL 中使用“view”而不是“edit”的输出可能看起来是空白的,但查看源代码将显示 Jupyter 提供了一个格式正确的 HTML 页面对格式正确的文件的引用,但某些东西阻止了文件进入 PDF 渲染器(或任何您需要的 DB 文件)。
I am still working on the complete solution, which involves some settings for the Jupyter server that we haven't figured out yet. I'll come back and edit this post when the solution is found. However, be assured that UTF-8 encoding is not the root cause here,at least as far as the file itself is concerned.
我仍在研究完整的解决方案,其中涉及我们尚未弄清楚的 Jupyter 服务器的一些设置。找到解决方案后,我会回来编辑这篇文章。但是,请放心,UTF-8 编码不是这里的根本原因,至少就文件本身而言。