我正在尝试将希伯来语字母插入我的数据库(mysql) 使用请求.窗体['some_input']
这是myinit.py的代码:
if request.method == "POST":
malfunction_opener = request.form['MalfunctionOpener']
malfunction_handler = request.form['malfunctionHandler']
system = request.form['system']
unit = request.form['unit']
我知道所发生的事情是对我所得到的信息进行编码/解码,但我不能让它成功。 我也尝试过获取_数据,将其编码为utf-8,获得它的字符串值,但没有成功。在
在许多其他帖子中,我看到它必须:
^{pr2}$我也这么做了。在
当我试图插入任何希伯来语字母时,总是会出现这个错误,例如:“שלום”
2017-05-02 17:35:23,930 - Rotating Log - ERROR - 'ascii' codec can't encode
characters in position 0-3: ordinal not in range(128)
2017-05-02 17:35:23,931 - Rotating Log - ERROR -
request.form['malfunctionDescription'] value is: שלו×
2017-05-02 17:35:23,932 - Rotating Log - ERROR -
Traceback (most recent call last):
File "/var/www/WebApp/WebApp/__init__.py", line 166, in new_malfunction
thwart(malfunction_description), thwart(malfunction_solution),
thwart(malfunction_summary),))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3:
ordinal not in range(128)
也许这是相关的,但另一个问题是当我把希伯来语字母直接插入mysql并将其导入到myweb时,我得到了这些问题的标记。 (但在mysql中我可以看到希伯来语字母)。在
谢谢!在
<;----------使用额外代码编辑------------------------------->
if len(str(request.form['malfunctionDescription'])) <= 0:
flash("You must enter a description.")
return render_template("new-malfunction.html", contacts=contacts, systems=systems, units=units)
else:
malfunction_description = request.form['malfunctionDescription']
if status == 0 and len(str(request.form['malfunctionSolution'])) <= 0:
flash("You must enter a solution.")
return render_template("new-malfunction.html", contacts=contacts, systems=systems, units=units)
else:
malfunction_solution = request.form['malfunctionSolution']
if status == 0 and len(str(request.form['malfunctionSummary'])) <= 0:
flash("You must enter a summary.")
return render_template("new-malfunction.html", contacts=contacts, systems=systems, units=units)
else:
malfunction_summary = request.form['malfunctionSummary']
x = c.execute("SELECT * FROM malfunctions WHERE malfunctionDescription = (%s)",
(malfunction_description,))
if int(x) > 0:
flash("You have already enter this malfunction")
return render_template("new-malfunction.html", contacts=contacts, systems=systems, units=units)
else:
c.execute(
"INSERT INTO malfunctions (status, openingTime, closingTime, malfunctionOpener, malfunctionHandler, system, unit, rank, malfunctionDescription, malfunctionSolution, malfunctionSummary) VALUES (%s,%s,%s, %s, %s, %s, %s, %s, %s, %s, %s)",
(thwart(status), thwart(opening_date), thwart(closing_date), thwart(malfunction_opener),
thwart(malfunction_handler), thwart(system), thwart(unit), thwart(rank),
thwart(malfunction_description), thwart(malfunction_solution), thwart(malfunction_summary),))
<;----------更新------------------------------->
我发现了我的第一个问题-我已经试着去拿眼镜了(请求.窗体['faultunctionopener']),它提供了这个胡言乱语×)לו×并给了我一个错误
我也试着输入我的数据库代表(请求.窗体['faultunctionopener']),它给了我这个类型的u'\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\'(只是一个示例),但我不知道如何从数据库中获取此信息并将其更改为希伯来语。
שלו×
是שלו
的“Mojibake”,见Trouble with utf8 characters; what I see is not what I stored\u203e
是Ë
的Unicode;我怀疑这是一个红鲱鱼。在更多关于python的notes。在
相关问题 更多 >
编程相关推荐