submit special character with genshi

34 views
Skip to first unread message

Enrico Heller

unread,
Oct 22, 2013, 3:47:21 AM10/22/13
to gen...@googlegroups.com
Hello there,

just another question. If i try to submit special character like german ö-ä-ü genshi dies with this error msg. How i make genshi able to show this?

Genshi UnicodeDecodeError error while rendering template '/tmp/Trachelloworld-1.1-py2.6.egg-tmp/helloworld/templates/helloworld.html', line 17, char -1

Thnx for help.

Simon Cross

unread,
Oct 22, 2013, 3:53:40 AM10/22/13
to gen...@googlegroups.com
Hi Enrico

Could you give a small example that fails for you and your Genshi
version and Python version (2 or 3)? The most likely reason is this if
failing is that you have gotten some minor detail of encodings wrong.

Genshi 0.6.x expects UTF-8 encoded strings by default. Genshi 0.7.x
expects unicode by default.

Schiavo
Simon

Enrico Heller

unread,
Oct 22, 2013, 8:38:28 AM10/22/13
to gen...@googlegroups.com
Hello Simon,

PlugIn

  1 # Helloworld plugin
  2
  3 import re
  4 import MySQLdb
  5
  6 from genshi.builder import tag
  7 from trac.core import *
  8 from trac.web import IRequestHandler
  9 from trac.web.chrome import INavigationContributor, ITemplateProvider, add_stylesheet
.
.
.
 61     def _page_data(self, req):
 62         title = "Test"
 63         wert = "Testwert"
 64         return {'title': title}
.
.
.
103         data['test'] = 'schön'
104         return 'helloworld.html', data, None



Template

  1 <!DOCTYPE html
  2     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4 <html xmlns="http://www.w3.org/1999/xhtml"
  5       xmlns:py="http://genshi.edgewall.org/"
  6       xmlns:xi="http://www.w3.org/2001/XInclude">
  7   <xi:include href="layout.html" />
  8   <head>
.
.
.
 46                 <p>$i{test}</p>
.
.
.


Trac Error

Genshi UnicodeDecodeError error while rendering template '/tmp/Trachelloworld-1.1-py2.6.egg-tmp/helloworld/templates/helloworld.html', line 46, char -1

If i change the variable to:

103         data['test'] = 'schoen'
104         return 'helloworld.html', data, None

it works..

My System:

System Information

Trac 0.12.3
Genshi 0.6.1
mod_python 3.3.1
pysqlite 2.4.1
Python 2.6.8 (unknown, May 29 2012, 22:30:44) [GCC 4.3.4 [gcc-4_3-branch revision 152973]]
setuptools 0.6c8
SQLite 3.7.6.3
jQuery:1.4.4


Thanks 4 your help

Simon Cross

unread,
Oct 22, 2013, 8:40:57 AM10/22/13
to gen...@googlegroups.com
On Tue, Oct 22, 2013 at 2:38 PM, Enrico Heller <ehel...@googlemail.com> wrote:
> 103 data['test'] = 'schön'

Try making this u'schön' ?

Felix Schwarz

unread,
Oct 22, 2013, 9:04:27 AM10/22/13
to gen...@googlegroups.com
But then you'll need to declare the encoding also in the Python file in the
first line:
#encoding: utf-8

Alternatively you should be able to write:
data['test'] = u'sch\xf6n'

@Enrico: Looks like you don't fully understand the differences between
unicode, utf-8, encoding in Python 2 - not that I blame you, because it is a
bit tricky especially when other languages uses unicode and utf-8 as synonms.
But basically when you want non-ascii characters in a string as rule of thumb
you should use u'...'.

fs

Reply all
Reply to author
Forward
0 new messages