facebook/tornado — Issue #407: Ability to override encoding used in get_argument() maybe
Author: peterbe
Created: 2011-12-01 00:27:20+00:00
State: open

I have another site that uses the latin-1 charset. Aka. iso-8859-1. It's got a form that submits to my tornado app (on a complete different domain name). When someone types in unicode, click submit and goes to my tornado server my tornado server fails on `self.get_argument('foo')` because it's the wrong encoding.

This is what ``self.request.arguments`` looks like:

```
{'foo': ['J\xf6nk\xf6ping']}
```

So trying to decode that fails with utf-8.

```python
>>> x
'J\xf6nk\xf6ping'
>>> unicode(x, 'utf-8')
Traceback (most recent call last):
File "", line 1, in
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 1: invalid start byte
>>> unicode(x, 'latin-1')
u'J\xf6nk\xf6ping'
```

If I could do this:

```python
foo = self.get_argument('foo', encoding='latin1')
```

or this:

```python
try:
foo = self.get_argument('foo')
except UnicodeDecodeError:
foo = self.get_argument('foo', encoding='latin1')
```

What do you think? I could whip up a pull request to continue the discussion there if you like.