Whats the simplest and safest method to generate a API KEY and SECRET in Python
问题 I need to generate a API key and Secret that would be stored in a Redis server. What would be the best way to generate a key and secret? I am develop a Django-tastypie framework based app. 回答1: EDIT: for a very secure way of generating random number, you should use urandom: from binascii import hexlify key = hexlify(os.urandom(length)) this will produce bytes, call key.decode() if you need a string You can just generate keys of your desired length the python way: import random import string