*
Inserting a new user programmatically with web2py, v2.4.6
I apologize for the re post. I have read many threads on this subject,
including several from Massimo, but I am still having trouble inserting a
new user record.
I just upgraded web2py to 2.4.6 from version 2012/3/4 1.99.7. The insert
was working before the upgrade.
When I execute the following code I receive the traceback below
code fragment:
...
password = json.loads(request.vars.password).decode('unicode-escape')
password = str(db.auth_user.password.validate(password)[0])
...
db.auth_user.insert(first_name=first_name, last_name=last_name,
email=email, password=password)
...
The above code was tried with and without " **.decode('unicode-escape') "
Error:
Traceback (most recent call last):
File
"/Users/foo/Desktop/dev/web2py/applications/init/controllers/default.py",
line 599, in manageUsers
password=str(db.auth_user.password.validate(password)[0]).decode('unicode-escape'))
File "/Users/foo/Desktop/dev/web2py/gluon/validators.py", line 2760, in str
hashed = simple_hash(self.password, key, salt, digest_alg)
File "/Users/foo/Desktop/dev/web2py/gluon/utils.py", line 87, in simple_hash
int(keylen), get_digest(alg))
File "/Users/foo/Desktop/dev/web2py/gluon/contrib/pbkdf2.py", line 55, in
pbkdf2_hex
return pbkdf2_bin(data, salt, iterations, keylen, hashfunc).encode('hex')
File "/Users/foo/Desktop/dev/web2py/gluon/contrib/pbkdf2.py", line 65, in
pbkdf2_bin
mac = hmac.new(data, None, hashfunc)
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
Important: When I execute the following code from the web2py shell using “
python web2py.py -S init -M “, I do not get an error and the insert works
as expected.
email = '[email protected]'
first_name='first'
last_name=’last'
password='flast123'
# web2py database portion...
db.auth_user.insert(first_name=first_name, last_name=last_name, email=email,
password=str(db.auth_user.password.validate(‘mySecretPassword')[0]))
Any insight is greatly appreciated!!
Thanks in advance,
Stan
*
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.