Pylons/webob — Issue #11: don't try to encode unicode as latin1
Author: evgeni
Created: 2011-11-21 14:04:46+00:00
State: open

The fix for http://trac.pythonpaste.org/pythonpaste/ticket/251 introduced the following code:
if isinstance(value, text_type) and not PY3:
value = value.encode('latin-1')
As unicode >> latin1 (latin1 does not even contain a simple €) and I don't understand why headers should be latin-1 anyways (my understanding is they have to be ascii), the following code breaks badly:
```>>> from webob import Response
>>> resp = Response()
>>> resp.etag = u'€'
Traceback (most recent call last):
File "", line 1, in
File "webob/descriptors.py", line 138, in fset
hset(r, val)
File "webob/descriptors.py", line 112, in fset
value = value.encode('latin-1')
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u20ac' in position 1: ordinal not in range(256)```

I would suggest `value = value.encode('ascii', 'ignore')` here (just to be safe, noone should actually pass non-ascii here, but you never know).