Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python on Dotcloud Crashes on certain functions

so I'm running a flask python app on dotcloud, and I'm basically trying to hash a password (using hashlib.sha512; the salt is uuid.uuid4().bytes).

user_dict['salt'] = uuid.uuid4().bytes
print_stderr(user_dict['salt'])
print_stderr(hashlib.sha512(user_dict['pwd'] + user_dict['salt']))
user_dict['pwd'] = hashlib.sha512(user_dict['pwd'] + user_dict['salt']).digest()
print_stderr(user_dict['pwd'])

This all works fine even in a python interpreter on dotcloud, but when I actually run the code on the server, it crashes (or something, the client gets a HTTP 500 code, but dotcloud logs just closes).

I can tell by which print statements are executed and which are not, that it crashes on the uuid.uuid4().bytes line. But if I replace that with a constant (e.g. "uehg83yydh") it doesn't fail immediately, rather on the hashlib.sha512(...).digest() line.

You may also notice that print_stderr is not a standard python function. It's a hack I am using to get dotcloud to print stuff from python (it prints to stderr instead of stdout). Surely there's a better way to debug on dotcloud that I'm not aware of?

like image 852
geniass Avatar asked Aug 11 '26 00:08

geniass


1 Answers

Try this for your code.

  1. Switching uuid to hex instead of bytes
  2. changing to use update() instead of adding the strings together, it is a little cleaner.

Code:

>>> user_dict['salt'] = uuid.uuid4().hex
>>> print_stderr(user_dict['salt'])
>>> import hashlib
>>> m = hashlib.sha512()
>>> m.update(user_dict['pwd'])
>>> m.update(user_dict['salt'])
>>> user_dict['pwd'] = m.hexdigest()
>>> print_stderr(user_dict['pwd'])
like image 84
Ken Cochrane Avatar answered Aug 13 '26 20:08

Ken Cochrane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!