我遇到了一个典型的 utf-8 编码问题,但到目前为止我还无法解决它。
class StatsTandE(webapp2.RequestHandler):
def get(self):
conn = rdbms.connect(instance=_INSTANCE_NAME, database='origami')
cursor = conn.cursor()
cursor.execute('SELECT ui.displayName, ui.title, ui.costCenter FROM views AS v')
results = [[str(row[0]), str(row[1]), str(row[2])] for row in cursor.fetchall()]
logging.info('results identified as %s', results)
template_file_name = 'templates/stats_results.html'
template_values = {
'results': results,
}
path = os.path.join(os.path.dirname(__file__), template_file_name)
self.response.out.write(template.render(path, template_values))
conn.close()
我看到的错误是:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 4: ordinal not in range(128)
改str(row[0])
了str(row[0]).encode('utf-8')
也没用。。。
有什么建议么?