I have written a very simple function for testing auth; via REST:
@service.jsondef login():
try:
args = json.loads(request.body.read())
username = HTMLParser.unescape.__func__(HTMLParser, args['user'])
password = HTMLParser.unescape.__func__(HTMLParser, args['pass'])
return dict(auth_succeeded=str(auth.login_bare(username, password)))
except ValueError, KeyError:
raise HTTP(400, 'Invalid data received')
Unfortunately this gives me the following traceback:
Traceback (most recent call last):
File "web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
File "web2py\applications\foo\controllers/api.py", line 35, in <module>
File "web2py\gluon\globals.py", line 193, in <lambda>
self._caller = lambda f: f()
File "web2py\applications\foo\controllers/api.py", line 16, in login
return dict(auth_succeeded=str(auth.login_bare(username, password)))
File "web2py\gluon\tools.py", line 1798, in login_bare
if not user.registration_key and password == user[passfield]:
File "web2py\gluon\validators.py", line 2654, in __eq__
h = simple_hash(self.password, key, salt, digest_alg)
File "web2py\gluon\utils.py", line 81, in simple_hash
int(keylen), get_digest(alg))
File "web2py\gluon\contrib\pbkdf2.py", line 55, in pbkdf2_hex
return pbkdf2_bin(data, salt, iterations, keylen,
hashfunc).encode('hex')
File "web2py\gluon\contrib\pbkdf2.py", line 65, in pbkdf2_bin
mac = hmac.new(data, None, hashfunc)
File "C:\usr\bin\Python27\lib\hmac.py", line 133, in new
return HMAC(key, msg, digestmod)
File "C:\usr\bin\Python27\lib\hmac.py", line 72, in __init__
self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode
How do I get this simple test-case working?
Thanks for all suggestions,
Alec Taylor
--