Forums

Stuck on beginners guide Flask + SQL db.create_all() error

I'm getting this huge error lol. I've followed verbatim the steps.

In [23]: db.create_all()

MySQLInterfaceError Traceback (most recent call last) /usr/local/lib/python3.6/site-packages/mysql/connector/connection_cext.py in _open_connection(self) 232 try: --> 233 self._cmysql.connect(**cnx_kwargs) 234 except MySQLInterfaceError as exc:

MySQLInterfaceError: Access denied for user 'ProgrammingByAnd'@'10.0.0.232' (using password: YES)

During handling of the above exception, another exception occurred:

ProgrammingError Traceback (most recent call last) /usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection) 2335 try: -> 2336 return fn() 2337 except dialect.dbapi.Error as e:

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in connect(self) 363 if not self._use_threadlocal: --> 364 return _ConnectionFairy._checkout(self) 365

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in _checkout(cls, pool, threadconns, fairy) 777 if not fairy: --> 778 fairy = _ConnectionRecord.checkout(pool) 779

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in checkout(cls, pool) 494 def checkout(cls, pool): --> 495 rec = pool._do_get() 496 try:

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/impl.py in _do_get(self) 139 with util.safe_reraise(): --> 140 self._dec_overflow() 141 else:

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py in exit(self, type_, value, traceback) 69 exc_value, ---> 70 with_traceback=exc_tb, 71 )

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_(failed resolving arguments) 181 try: --> 182 raise exception 183 finally:

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/impl.py in _do_get(self) 136 try: --> 137 return self._create_connection() 138 except:

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in _create_connection(self) 308 --> 309 return _ConnectionRecord(self) 310

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in init(self, pool, connect) 439 if connect: --> 440 self.__connect(first_connect_check=True) 441 self.finalize_callback = deque()

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in __connect(self, first_connect_check) 660 with util.safe_reraise(): --> 661 pool.logger.debug("Error on connect(): %s", e) 662 else:

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py in exit(self, type_, value, traceback) 69 exc_value, ---> 70 with_traceback=exc_tb, 71 )

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_(failed resolving arguments) 181 try: --> 182 raise exception 183 finally:

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in __connect(self, first_connect_check) 655 self.starttime = time.time() --> 656 connection = pool._invoke_creator(self) 657 pool.logger.debug("Created new connection %r", connection)

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py in connect(connection_record) 113 return connection --> 114 return dialect.connect(cargs, *cparams) 115

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/default.py in connect(self, cargs, cparams) 508 # inherits the docstring from interfaces.Dialect.connect --> 509 return self.dbapi.connect(cargs, **cparams) 510

/usr/local/lib/python3.6/site-packages/mysql/connector/init.py in connect(args, kwargs) 269 if HAVE_CEXT and not use_pure: --> 270 return CMySQLConnection(args, kwargs) 271 return MySQLConnection(*args, kwargs)

/usr/local/lib/python3.6/site-packages/mysql/connector/connection_cext.py in init(self, kwargs) 85 if kwargs: ---> 86 self.connect(kwargs) 87

/usr/local/lib/python3.6/site-packages/mysql/connector/abstracts.py in connect(self, **kwargs) 984 self.disconnect() --> 985 self._open_connection() 986 # Server does not allow to run any other statement different from ALTER

/usr/local/lib/python3.6/site-packages/mysql/connector/connection_cext.py in _open_connection(self) 235 raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno, --> 236 sqlstate=exc.sqlstate) 237

ProgrammingError: 1045 (28000): Access denied for user 'ProgrammingByAnd'@'10.0.0.232' (using password: YES)

The above exception was the direct cause of the following exception:

ProgrammingError Traceback (most recent call last) <ipython-input-23-653042798025> in <module> ----> 1 db.create_all()

/usr/local/lib/python3.6/site-packages/flask_sqlalchemy/init.py in create_all(self, bind, app) 1037 Parameters were added 1038 """ -> 1039 self._execute_for_all_tables(app, bind, 'create_all') 1040 1041 def drop_all(self, bind='all', app=None):

/usr/local/lib/python3.6/site-packages/flask_sqlalchemy/init.py in _execute_for_all_tables(self, app, bind, operation, skip_tables) 1029 extra['tables'] = tables 1030 op = getattr(self.Model.metadata, operation) -> 1031 op(bind=self.get_engine(app, bind), **extra) 1032 1033 def create_all(self, bind='all', app=None):

/usr/local/lib/python3.6/site-packages/sqlalchemy/sql/schema.py in create_all(self, bind, tables, checkfirst) 4552 bind = _bind_or_error(self) 4553 bind._run_visitor( -> 4554 ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables 4555 ) 4556

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _run_visitor(self, visitorcallable, element, connection, kwargs) 2092 self, visitorcallable, element, connection=None, kwargs 2093 ): -> 2094 with self._optional_conn_ctx_manager(connection) as conn: 2095 conn._run_visitor(visitorcallable, element, **kwargs) 2096

/usr/local/lib/python3.6/contextlib.py in enter(self) 79 def enter(self): 80 try: ---> 81 return next(self.gen) 82 except StopIteration: 83 raise RuntimeError("generator didn't yield") from None

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _optional_conn_ctx_manager(self, connection) 2084 def _optional_conn_ctx_manager(self, connection=None): 2085 if connection is None: -> 2086 with self._contextual_connect() as conn: 2087 yield conn 2088 else:

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _contextual_connect(self, close_with_result, kwargs) 2300 return self._connection_cls( 2301 self, -> 2302 self._wrap_pool_connect(self.pool.connect, None), 2303 close_with_result=close_with_result, 2304 kwargs

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection) 2338 if connection is None: 2339 Connection._handle_dbapi_exception_noconnection( -> 2340 e, dialect, self 2341 ) 2342 else:

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in handle_dbapi_exception_noconnection(cls, e, dialect, engine) 1582 elif should_wrap: 1583 util.raise( -> 1584 sqlalchemy_exception, with_traceback=exc_info[2], from_=e 1585 ) 1586 else:

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_(failed resolving arguments) 180 181 try: --> 182 raise exception 183 finally: 184 # credit to

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection) 2334 dialect = self.dialect 2335 try: -> 2336 return fn() 2337 except dialect.dbapi.Error as e: 2338 if connection is None:

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in connect(self) 362 """ 363 if not self._use_threadlocal: --> 364 return _ConnectionFairy._checkout(self) 365 366 try:

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in _checkout(cls, pool, threadconns, fairy) 776 def _checkout(cls, pool, threadconns=None, fairy=None): 777 if not fairy: --> 778 fairy = _ConnectionRecord.checkout(pool) 779 780 fairy._pool = pool

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in checkout(cls, pool) 493 @classmethod 494 def checkout(cls, pool): --> 495 rec = pool._do_get() 496 try: 497 dbapi_connection = rec.get_connection()

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/impl.py in _do_get(self) 138 except: 139 with util.safe_reraise(): --> 140 self._dec_overflow() 141 else: 142 return self._do_get()

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py in exit(self, type_, value, traceback) 68 compat.raise_( 69 exc_value, ---> 70 with_traceback=exc_tb, 71 ) 72 else:

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_(failed resolving arguments) 180 181 try: --> 182 raise exception 183 finally: 184 # credit to

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/impl.py in _do_get(self) 135 if self._inc_overflow(): 136 try: --> 137 return self._create_connection() 138 except: 139 with util.safe_reraise():

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in _create_connection(self) 307 """Called by subclasses to create a new ConnectionRecord.""" 308 --> 309 return _ConnectionRecord(self) 310 311 def _invalidate(self, connection, exception=None, _checkin=True):

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in init(self, pool, connect) 438 self.__pool = pool 439 if connect: --> 440 self.__connect(first_connect_check=True) 441 self.finalize_callback = deque() 442

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in __connect(self, first_connect_check) 659 except Exception as e: 660 with util.safe_reraise(): --> 661 pool.logger.debug("Error on connect(): %s", e) 662 else: 663 if first_connect_check:

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py in exit(self, type_, value, traceback) 68 compat.raise_( 69 exc_value, ---> 70 with_traceback=exc_tb, 71 ) 72 else:

/usr/local/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_(failed resolving arguments) 180 181 try: --> 182 raise exception 183 finally: 184 # credit to

/usr/local/lib/python3.6/site-packages/sqlalchemy/pool/base.py in __connect(self, first_connect_check) 654 try: 655 self.starttime = time.time() --> 656 connection = pool._invoke_creator(self) 657 pool.logger.debug("Created new connection %r", connection) 658 self.connection = connection

/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py in connect(connection_record) 112 if connection is not None: 113 return connection --> 114 return dialect.connect(cargs, cparams) 115 116 creator = pop_kwarg("creator", connect) /usr/local/lib/python3.6/site-packages/sqlalchemy/engine/default.py in connect(self, cargs, cparams) 507 def connect(self, *cargs, cparams): 508 # inherits the docstring from interfaces.Dialect.connect --> 509 return self.dbapi.connect(cargs, cparams) 510 511 def create_connect_args(self, url): /usr/local/lib/python3.6/site-packages/mysql/connector/init.py in connect(args, kwargs) 268 269 if HAVE_CEXT and not use_pure: --> 270 return CMySQLConnection(*args, kwargs) 271 return MySQLConnection(args, kwargs) 272 Connect = connect # pylint: disable=C0103 /usr/local/lib/python3.6/site-packages/mysql/connector/connection_cext.py in init(self, kwargs) 84 85 if kwargs: ---> 86 self.connect(kwargs) 87 88 def _add_default_conn_attrs(self): /usr/local/lib/python3.6/site-packages/mysql/connector/abstracts.py in connect(self, *kwargs) 983 984 self.disconnect() --> 985 self._open_connection() 986 # Server does not allow to run any other statement different from ALTER 987 # when user's password has been expired. /usr/local/lib/python3.6/site-packages/mysql/connector/connection_cext.py in _open_connection(self) 234 except MySQLInterfaceError as exc: 235 raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno, --> 236 sqlstate=exc.sqlstate) 237 238 self._do_handshake() ProgrammingError: (mysql.connector.errors.ProgrammingError) 1045 (28000): Access denied for user 'ProgrammingByAnd'@'10.0.0.232' (using password: YES) (Background on this error at: http://sqlalche.me/e/13/f405)

You're using the wrong password. You need to use the password that you set on you Databases page when you enabled MySQL.

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:

    {password}@{hostname}/{databasename}".format (

        username="ProgrammingByAnd",

        password="hidden", (hidden for security reasons)

        hostname="ProgrammingByAndrew.mysql.pythonanywhere-services.com",

        databasename="ProgrammingByAnd$comments",

I've changed the passcode over and over to the passcode I am currently using in this code? Yes it is taking my passcode when I try to change it. I'm actively getting a notification "Your MySQL password has been changed." So no "too common" or "not long enough" errors. Still No matter how many times I try to line things up it doesn't work

Edit: When I type db in the console this is what I get

<SQLAlchemy engine=mysql+mysqlconnector://ProgrammingByAnd:***@ProgrammingByAndrew.mysql.pythonanywhere-services.com/ProgrammingByAnd$comments?charset=utf8>

FIXED! THANK YOU.

Need to type exit, that will take you back into the mysite folder, Then type ipython3.x to refresh the console.

Long story short, changing my passcode wasnt going to work because I never refreshed the console.

Glad to her that you made it work!