Note that there are some explanatory texts on larger screens.

plurals
  1. POPyMongo failing to connect to Heroku MongoLab add-on
    primarykey
    data
    text
    <p>I've added the MongoLab add-on to a Heroku instance, but my app won't connect to the MongoDB host. I've seen <a href="https://stackoverflow.com/questions/8859532/how-can-i-use-the-mongolab-add-on-to-heroku-from-python">this</a> thread, but I didn't see anything helpful.</p> <p><strong>twitter_clone_python.py</strong></p> <pre><code>f = Flask(__name__) # 'TheFuture' is the name of my laptop. It signifies that we are in # development mode. if socket.gethostname().startswith('TheFuture'): f.config.from_object('config.DevelopmentConfig') # If 'TheFuture' isn't the host, then we are in production. else: f.config.from_object('config.ProductionConfig') # 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: pass </code></pre> <p><strong>config.py</strong></p> <pre><code>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:] class DevelopmentConfig(Config): '''Configuration object specific to development environments.''' DEBUG = True MONGODB_HOST = 'localhost' MONGODB_PORT = 27017 MONGODB_DB = 'twitter-clone-python-development' </code></pre> <p>Running <code>heroku logs</code> shows the error:</p> <pre><code>2012-09-28T13:57:25+00:00 app[web.1]: pymongo.errors.AutoReconnect: could not connect to ds037997.mongolab.com:27017: timed out </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload