New submission from arexus <asweene...@gmail.com>:

When following the 2-legged flow example provided I am experiencing the 
following error:

TypeError: character mapping must return integer, None or unicode

This is caused by a unicode string being passed to the HMAC(...) function.  I 
have 
traced everything back to the root of the problem and it turns out that this is 
caused by using a sqlite database with sqlalchemy.

http://www.sqlalchemy.org/docs/dialects/sqlite.html#unicode

What happens is:
cons = Consumer()
cons.key = 'test'
cons.secret = 'test'
cons.name = 'test'
Session.add(cons)
Session.commit()

type(cons.key) will become unicode.

A really poor workaround is to add the following to to the 
get_consumer_by_key() 
function:
cons = self.DBSession.query(self.Consumer).filter_by(key=key).first()
cons.key.encode('ascii')
cons.secret.encode('ascii')

A better solution may be to store the key and string as binary.

----------
files: oauth_dump.txt
messages: 470
nosy: arexus
priority: bug
status: unread
title: oauth and unicode

__________________________________
Repoze Bugs <b...@bugs.repoze.org>
<http://bugs.repoze.org/issue173>
__________________________________
URL: 
http://127.0.0.1:5000/api/private?oauth_nonce=647164&oauth_timestamp=1293766491&oauth_consumer_key=andrew&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=gEJnamiTYEiu1NZFFAMGc6arpcI%3D
File 
'/Users/my-user/Development/my-project/mydevenv/lib/python2.7/site-packages/WebError-0.10.3-py2.7.egg/weberror/evalexception.py',
 line 431 in respond
  app_iter = self.application(environ, detect_start_response)
File 
'/Users/my-user/Development/my-project/mydevenv/lib/python2.7/site-packages/repoze.who-1.0.18-py2.7.egg/repoze/who/middleware.py',
 line 69 in __call__
  auth_ids = self.authenticate(environ, classification, ids)
File 
'/Users/my-user/Development/my-project/mydevenv/lib/python2.7/site-packages/repoze.who-1.0.18-py2.7.egg/repoze/who/middleware.py',
 line 201 in authenticate
  userid = plugin.authenticate(environ, identity)
File 
'/Users/my-user/Development/my-project/mydevenv/lib/python2.7/site-packages/repoze_oauth_plugin-0.2-py2.7.egg/repoze/who/plugins/oauth/plugin.py',
 line 264 in authenticate
  if not validator(self, env):
File 
'/Users/my-user/Development/my-project/mydevenv/lib/python2.7/site-packages/repoze_oauth_plugin-0.2-py2.7.egg/repoze/who/plugins/oauth/plugin.py',
 line 184 in _verify_request
  self.server.verify_request(req, env['consumer'], env.get('token'))
File 'build/bdist.macosx-10.5-fat3/egg/oauth2/__init__.py', line 602 in 
verify_request
File 'build/bdist.macosx-10.5-fat3/egg/oauth2/__init__.py', line 652 in 
_check_signature
File 'build/bdist.macosx-10.5-fat3/egg/oauth2/__init__.py', line 705 in check
File 'build/bdist.macosx-10.5-fat3/egg/oauth2/__init__.py', line 738 in sign
File '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py', 
line 133 in new
  return HMAC(key, msg, digestmod)
File '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py', 
line 72 in __init__
  self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode

_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to