【问题标题】:Django encoding error when querying the DB查询数据库时出现 Django 编码错误
【发布时间】:2014-08-21 20:58:38
【问题描述】:

我正在使用 Neomodel 库将我的 Neo4j 数据库与 Django 框架绑定。 尝试通过本地 shell 从我的数据库中获取实例,我收到编码错误:

city = PlaceName.index.search(name=u'Zürich')

UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal not in range(128)

我怎样才能避免这种情况?

【问题讨论】:

  • 您确定您的表格编码正确吗? utf-8 ?
  • PlaceName 是一个类:class PlaceName(StructuredNode): name = StringProperty(index=True, required=True) lang = StringProperty(index=True, required=True) type = StringProperty(index=True, required=True) hasid = RelationshipTo('PlaceId', 'HAS_ID') descr = RelationshipTo('Desc', 'HAS_DESC')
  • 但它与您的数据库有关,例如 MySQL stackoverflow.com/questions/3832056/…
  • 我使用图形数据库 NoSQL,我没有这种表
  • 但是您仍然需要为您的文本数据选择某种编码。如果您没有选择我建议您查看该字段的默认编码以及如何更改它,最好是 UTF8。

标签: django encoding neomodel


【解决方案1】:

嗯……

你能试试这个吗:

city = PlaceName.index.search(name=unicode('Zürich','utf-8'))

【讨论】:

  • 完全相同的错误,但感谢您的帮助
  • 对不起,伙计;/我已经尽力了。
猜你喜欢
  • 2017-04-13
  • 2020-04-07
  • 2012-12-04
  • 1970-01-01
  • 2014-08-17
  • 2015-05-25
  • 2023-04-05
  • 2020-04-21
  • 1970-01-01
相关资源
最近更新 更多