I'm developping a small web service in python using:
- Flask (v. 0.8)
- storm ORM (v. 0.19)
- Apache with mod_wsgi
I have a custom HTTP header, Unison-UUID
which I'm using at some point to retrieve information in my database.
here's the (slightly rewritten for simplicity) snippet that I'm having trouble with:
uuid = flask.request.headers['Unison-UUID']
store = storm.locals.Store(my_database)
user = store.get(models.User, uuid)
The class User
is more or less like this:
class User(Storm):
uuid = Unicode(primary=True)
# Other columns....
The code above fails in the following way:
File "/Users/lum/Documents/unison-recsys/www/api/unison/unison.py", line 27, in decorated
user = g.store.get(models.User, uuid)
File "/Users/lum/Documents/unison-recsys/venv/lib/python2.6/site-packages/storm/store.py", line 165, in get
variable = column.variable_factory(value=variable)
File "/Users/lum/Documents/unison-recsys/venv/lib/python2.6/site-packages/storm/variables.py", line 396, in parse_set
% (type(value), value))
TypeError: Expected unicode, found <type 'str'>: '00000000-0000-0000-0000-000000000009'
I don't really understand why this is happening and what I can do about it. I thought Flask was 100% unicode.
A quick fix I found is to decode the header value, i.e uuid = uuid.decode('utf-8')
. Is this really what needs to be done? This seems a bit hackish. Is there no way to get unicode directly, without having to "decode" it manually?