在服务器上重启后UnicodeDecodeError

时间:2015-06-24 08:17:55

标签: python

我实现了一个名为Odoo / OpenERP的产品,最近在更改多个文件中的某些字符串后执行了重启。

这些字符串包含没有重音字符的标准字符。重新启动后,对网站的任何访问都会产生以下结果:

2015-06-24 08:09:35,884 1584 ERROR XXXXXX-Odoo-Production werkzeug: Error on request:

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)

File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)

File "/opt/odoo-production/openerp/service/server.py", line 290, in app
return self.app(e, s)


File "/opt/odoo-production/openerp/service/wsgi_server.py", line 216, in application
return application_unproxied(environ, start_response)


File "/opt/odoo-production/openerp/service/wsgi_server.py", line 202, in application_unproxied
result = handler(environ, start_response)


File "/opt/odoo-production/openerp/http.py", line 1290, in __call__
return self.dispatch(environ, start_response)


File "/opt/odoo-production/openerp/http.py", line 1264, in __call__
return self.app(environ, start_wrapped)


File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 579, in __call__
return self.app(environ, start_response)


File "/opt/odoo-production/openerp/http.py", line 1426, in dispatch
ir_http = request.registry['ir.http']


File "/opt/odoo-production/openerp/http.py", line 346, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None


File "/opt/odoo-production/openerp/modules/registry.py", line 339, in get
update_module)


File "/opt/odoo-production/openerp/modules/registry.py", line 356, in new
registry = Registry(db_name)


File "/opt/odoo-production/openerp/modules/registry.py", line 60, in __init__
self._db = openerp.sql_db.db_connect(db_name)


File "/opt/odoo-production/openerp/sql_db.py", line 623, in db_connect
db, uri = dsn(to)


File "/opt/odoo-production/openerp/sql_db.py", line 614, in dsn
return db_or_uri, '%sdbname=%s' % (_dsn, db_or_uri)


UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 28: ordinal not in range(128)

我已经检查过我所做过的更改的文件,但这些似乎很好。

有谁知道我可以在哪里开始调试此问题?我对Python比较新,调试/理解这个跟踪是我不熟悉的。

1 个答案:

答案 0 :(得分:0)

因此,您必须使用unicode字符串,因为在处理字符串时,需要将其用作unicode,并且由于字符串类型为str而失败。您可以通过

将其变为unicode
mystring = unicode(mystring, 'utf-8')

这会将字符串的类型从str更改为unicode