Here is the code I'm using to try to authenticate:
# MongoDB connection
connection = Connection(f.config['MONGODB_HOST'], f.config['MONGODB_PORT'])
db = connection['MONGODB_DB']
# Try authenticating. This will only work in production. In development,
# MONGODB_USER and MONGODB_PASSWORD will raise KeyErrors.
try:
db.authenticate(f.config['MONGODB_USER'], f.config['MONGODB_PASSWORD'])
except KeyError:
f.logger.debug('KeyError: Not authenticating.')
# Temporary. This is just for testing purposes.
users = db.users
user = users.find_one({'username': 'BrewerOnRails'})
My configuration is loaded from an object called ProductionConfig:
class Config(object):
'''Default configuration object.'''
DEBUG = False
TESTING = False
PORT = int(os.environ.get('PORT', 5000))
class ProductionConfig(Config):
'''Configuration object specific to production environments.'''
REDIS_URL = os.environ.get('REDISTOGO_URL')
if REDIS_URL:
url = urlparse.urlparse(REDIS_URL)
REDIS_HOST = url.hostname
REDIS_PORT = url.port
REDIS_PASSWORD = url.password
MONGOLAB_URI = os.environ.get('MONGOLAB_URI')
if MONGOLAB_URI:
url = urlparse.urlparse(MONGOLAB_URI)
MONGODB_USER = url.username
MONGODB_PASSWORD = url.password
MONGODB_HOST = url.hostname
MONGODB_PORT = url.port
MONGODB_DB = url.path[1:]
Here is the error I keep getting:
pymongo.errors.OperationFailure: database error: unauthorized db:MONGODB_DB lock type:-1 client:10.117.107.165
The OperationFailure exception is raised by PyMongo's _unpack_response function in the helpers.py file, specifically lines 103 and 104.
This looks wrong to me:
db = connection['MONGODB_DB']
Perhaps you want
db = connection[config['MONGODB_DB']]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With