Skip to content

Instantly share code, notes, and snippets.

@abemusic
Created February 17, 2014 17:38
Show Gist options
  • Save abemusic/9055332 to your computer and use it in GitHub Desktop.
Save abemusic/9055332 to your computer and use it in GitHub Desktop.
# load the default settings
from django.conf import settings
settings.configure()
from django.db.utils import load_backend
from dj_database_url import parse
def try_dsn(dsn):
try:
db = parse(dsn)
db['OPTIONS'] = {}
mod = load_backend('django.db.backends.mysql')
wrapper = mod.DatabaseWrapper(db)
wrapper.cursor()
except Exception, e:
print e.args[1]
return
print 'SUCCESS!'
if __name__ == '__main__':
try_dsn('mysql://foo:bar@localhost:3306/dbname')
try_dsn('mysql://gooduser:password@localhost:3306/good_db')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment