6

I'm trying to connect to a MySQL database using Flask-SqlAlchemy, here's my parameter :

SQLALCHEMY_DATABASE_URI = 'mysql://root:[email protected]/database?charset=utf8'

But when I go to the url, I get this error :

AttributeError: 'tuple' object has no attribute 'drivername'

If I change the SQLALCHEMY_DATABASE_URI to sqlite:///db.sqlite, it works correctly.

What am I missing ?

Note: I also tried mysql+mysqldb://, without any luck.

3
  • 1
    Just a guess: you don't by any chance have an extra comma after your URL string, do you? Commented Oct 8, 2013 at 12:43
  • Man you're good ! :) (You can answer it, I'll upvote & validate the answer :)) Commented Oct 8, 2013 at 12:54
  • 1
    Can be put on hold under the official close reason: This question was caused by a problem that can no longer be reproduced or a simple typographical error. Commented Sep 25, 2018 at 9:06

1 Answer 1

25

This error often comes up due to their being an extra comma after the URL string. So, instead of...

SQLALCHEMY_DATABASE_URI = 'mysql://root:[email protected]/database?charset=utf8'

...you have...

SQLALCHEMY_DATABASE_URI = 'mysql://root:[email protected]/database?charset=utf8',

The extra comma turns the SQLALCHEMY_DATABASE_URI into a tuple with the string as the only value. SQLAlchemy will skip trying to parse the resulting tuple, but Flask-SQLAlchemy will still try to use the "parsed" result.

This is fixed by removing the extra comma.

Sign up to request clarification or add additional context in comments.

4 Comments

You're right, I switched from a dict configuration to an Object configuration, and I forgot to remove some coma... hence the error ... Thanks !
Your answer solved a totally different problem that I have been with a SQLAlchemy result, just realising its a tuple helped get my value! ie Go for myresult[0] instead of myresult
Thank you very much! I can only imagine how much time this issue would have taken from me to find it!
Clearly, the error message should link directly to this answer. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.