Ian Charnas wrote:
> On Apr 6, 1:44 pm, Fred C <[EMAIL PROTECTED]> wrote:
>
> > I got that error every time i have an url with "special" non ascii
> > characters. Is there a quick fix for that out there?
>
> > -fred-
>
> > 500 Internal error
>
> > The server encountered an unexpected condition which prevented it
> > from fulfilling the request.
>
> > Page handler: 'ordinal not in range(128)'
> > Traceback (most recent call last):
> >    File "/usr/pkg/lib/python2.4/site-packages/CherryPy-2.2.1-
> > py2.4.egg/cherrypy/_cphttptools.py", line 103, in _run
> >      applyFilters('before_main')
> >    File "/usr/pkg/lib/python2.4/site-packages/CherryPy-2.2.1-
> > py2.4.egg/cherrypy/filters/__init__.py", line 151, in applyFilters
> >      method()
> >    File "/usr/pkg/lib/python2.4/site-packages/CherryPy-2.2.1-
> > py2.4.egg/cherrypy/filters/decodingfilter.py", line 31, in before_main
> >      self.decode(enc)
> >    File "/usr/pkg/lib/python2.4/site-packages/CherryPy-2.2.1-
> > py2.4.egg/cherrypy/filters/decodingfilter.py", line 50, in decode
> >      decodedParams[key] = value.decode(enc)
> >    File "/usr/pkg/lib/python2.4/encodings/utf_8.py", line 16, in decode
> >      return codecs.utf_8_decode(input, errors, True)
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\xbb' in
> > position 14: ordinal not in range(128)
>
> Hmm... this one is tricky!  I researched this recently and found out
> that characters in a URL are limited to a subset of ASCII, and other
> characters are supposed to be escaped (like a space turns into "%20"
> for instance).  Of course this is a terrible thing, because it limits
> URLs to characters in the english language, completely ignoring most
> of the world.

Not really; it means that the user agent has to escape any non-ASCII
characters in the HTTP request, but it is free to display those
characters to the user in whatever encoding it likes. Most browsers
are good at doing this for the actual path, but query string params
(as Fred is apparently running into) are problematic, especially if
you form the URL yourself in javascript.

> So one answer would be that if you want your app to be
> able to run correctly through the vast web of proxy servers,
> firewalls, etc that comprise the internet, stick to the [awful]
> standard and don't use those characters in URLs without escaping
> them.  This is one way to avoid the error that you're getting.
>
> The question then is what should CherryPy do?  Should it follow the
> standard and return an error (like it's doing now), or should it
> include hacks to accept non-standard characters (this is what Apache
> has done).   I believe this is one for the CherryPy mailing list...
> I'll see if I can cross-post this to the cherrypy-devel google
> group...

CherryPy's going to stick with the standard. To pull one of the
examples from the test suite, the URL

    /Von Bülow?ID=14

should be encoded as:

    /Von%20B%fclow?ID=14

The problem with non-ASCII characters is that there isn't any standard
for specifying the charset of the encoded bits of the URL itself; the
best one can do is assume that a Content-Type request header's charset
applies to the query string (as well as the body). If you have some
control over the client, you can help CherryPy guess by setting the
"decoding_filter.encoding" config entry (to force a certain encoding
to be used) and/or the "decoding_filter.default_encoding" entry (to
fall back to a given encoding if the Content-Type request header is
missing or has no charset). Note also:

  "When no explicit charset parameter is provided
   by the sender, media subtypes of the "text" type
   are defined to have a default charset value of
   "ISO-8859-1" when received via HTTP."

If you need more information, try reading the source code for the
decoding filter; it's short and simple.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to