Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #366 (closed defect: fixed)

Opened 14 years ago

Last modified 12 years ago

Clueless Traceback

Reported by: fab@… Owned by: anonymous
Priority: high Milestone:
Component: TurboGears Version: 0.8
Severity: major Keywords:


I'm fighting with encodings and turbogears. TG seems to have weired rules about it, maybe an explicit guidline is a good idea. Adding to that, when an encoding error happends, we have *no* clue about the part of the developper code causing it. Here is an example:

500 Internal error

Server got itself in trouble

Traceback (most recent call last):

File "c:\python24\lib\site-packages\CherryPy?-2.1.0-py2.4.egg\cherrypy\_cphttptools.py", line 271, in run


File "c:\python24\lib\site-packages\CherryPy?-2.1.0-py2.4.egg\cherrypy\_cphttptools.py", line 502, in main

body = page_handler(*args, cherrypy.request.paramMap)

File "c:\python24\lib\site-packages\TurboGears-0.8a5-py2.4.egg\turbogears\controllers.py", line 122, in newfunc

return controllers._process_output(tg_format, output, html)

File "c:\python24\lib\site-packages\TurboGears-0.8a5-py2.4.egg\turbogears\controllers.py", line 38, in _process_output

output = view.render(output, tg_format, template=template)

File "c:\python24\lib\site-packages\TurboGears-0.8a5-py2.4.egg\turbogears\view.py", line 99, in render

return t.serialize(encoding="utf-8", output=format, fragment=fragment)

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\init.py", line 232, in serialize

return serializer.serialize(self, encoding, fragment)

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\serialization.py", line 51, in serialize

text = list(self.generate(stream, encoding, fragment))

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\serialization.py", line 319, in generate

for ev, item in self.apply_filters(stream):

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\serialization.py", line 77, in balancing_filter

for ev, item in stream:

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\pull.py", line 203, in _coalesce

for ev, item in stream:

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\filter.py", line 21, in transform_filter

for ev, item in apply_matches(stream, template, templates, apply_func):

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\filter.py", line 31, in apply_matches

item = stream.expand()

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\pull.py", line 95, in expand

for ev, item in self._iter:

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\pull.py", line 164, in _track

for p in stream:

File "c:\python24\lib\site-packages\kid-0.8-py2.4.egg\kid\pull.py", line 203, in _coalesce

for ev, item in stream:

File "C:\temp\rfsbrowser\rfsbrowser\templates\browse.py", line 80, in _pull File "c:\python24\lib\site-packages\TurboGears-0.8a5-py2.4.egg\turbogears\init.py", line 42, in url

args = ["%s=%s" % (key, urllib.quote(str(value)))

UnicodeEncodeError?: 'ascii' codec can't encode character u'\xf6' in position 14: ordinal not in range(128)

Powered by Cherrypy 2.1.0

Change History

comment:1 Changed 14 years ago by anonymous


import turbogears
from turbogears import controllers
import rfssh
rfs = rfssh.ReiserFS()

class Root(controllers.Root):

	def index(self):
		drives = rfs.getDrives()
		return dict(drives=drives)

	def browse(self,drive,dest,path="."):
		path = path.decode('utf8')
		rfs.setDrive( drive.split('.') )
		data=rfs.ls(path) # returns data with unicode strings
		return dict(path=path,drive=drive,files=data,dest=dest)
	def fetch(self,drive,dest,path):
		return dict(infos='',drive=drive,path=path.decode('utf8'),dest=dest)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"

		<meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
		<title>ReiserFS Browser</title>

		<h1>Listing ${path}</h1>
			<a href="${std.url('index')}">Drive selection page</a>
			<a href="${std.url('browse',dest=dest,drive=drive,path='/'.join(path.split('/')[:-1]).encode('utf8'))}">Parent directory</a>
			<li py:for="f in files">
			<span py:if="f.type == 'd'">
				<a href="${std.url('browse',dest=dest,drive=drive,path=path.encode('utf8')+'/'+f.filename.encode('utf8'))}">${f}</a>
					<a href="${std.url('fetch',dest=dest,drive=drive,path=path.encode('utf8')+'/'+f.filename.encode('utf8'))}">[GET DIRECTORY]</a>
			<span py:if="f.type != 'd'">
					<a href="${std.url('fetch',dest=dest,drive=drive,path=path.encode('utf8')+'/'+f.filename.encode('utf8'))}">[GET FILE]</a>

comment:2 Changed 14 years ago by anonymous

I think it is the kid-ticket:  http://lesscode.org/projects/kid/ticket/95

comment:3 Changed 14 years ago by anonymous

  • Status changed from new to assigned

comment:4 Changed 13 years ago by anonymous

The problem is this line which tries to coerce a unicode string into a normal string.

args = ["%s=%s" % (key, urllib.quote(str(value)))


str(unicode("Örjan", "utf8"))

Traceback (most recent call last):

File "<stdin>", line 1, in ?

UnicodeEncodeError?: 'ascii' codec can't encode character u'\xd6' in position 0: ordinal not in range(128)

I managed to work-around that problem by changing line 108 in util.py to:

args.append("%s=%s" % (key, urllib.quote(value.encode("utf8"))))

But it is not a good solution because the unicode-string should be encoded to the client's encoding, not always utf8.

comment:5 Changed 13 years ago by godoy

  • Status changed from assigned to closed
  • Component changed from CherryPy to TurboGears
  • Resolution set to fixed

I believe this is fixed in the trunk -- at least I'm not seeing any problems with Unicode there.

Also, please, take a look at http://trac.turbogears.org/turbogears/wiki/Internationalization for alternative approaches.

I'm closing this as fixed, but if it still is a problem for you, please reopen this ticket.

Note: See TracTickets for help on using tickets.