question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'MySQLConnection' object has no attribute 'execute'

See original GitHub issue

I am using chatterbot as follows:

from chatterbot import ChatBot
from sqlalchemy import create_engine
from sqlalchemy.pool import NullPool
from constants.database import *

 chatterbot = ChatBot(
        'Nicholas The Navigator',
        storage_adapter="chatterbot.storage.SQLStorageAdapter",
        logic_adapters=[
            {
                'import_path': 'chatterbot.logic.BestMatch'
            },
            {
                'import_path': 'chatterbot.logic.LowConfidenceAdapter',
                'threshold': 0.20,
                'default_response': 'I am sorry, but I cannot find things that you need. Maybe you should explore our website. '
            }
        ],
        trainer='chatterbot.trainers.ListTrainer'
    )

    chatterbot.train([
        "hi",
        "hello",
        "greetings!",
        "how are you?"
        "i am fine, thank you."
    ])

Upon writing the following code after this

# my sql connection for some custom tasks
# CONNECTION_STRING = 'mysql+mysqlconnector://userone:mypass@localhost/db_chatterbot'
my_engine = create_engine(CONNECTION_STRING, poolclass=NullPool).connect()

I am getting an error,

Traceback (most recent call last):
  File "D:/user.one/project/_analytics/Analytics/server.py", line 134, in <module>
    chatterbot = make_chatterbot()
  File "D:/user.one/project/_analytics/Analytics/server.py", line 128, in make_chatterbot
    my_engine = create_engine(CONNECTION_STRING, poolclass=NullPool).connect()
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 2102, in connect
    return self._connection_cls(self, **kwargs)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 90, in __init__
    if connection is not None else engine.raw_connection()
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 2188, in raw_connection
    self.pool.unique_connection, _connection)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 2158, in _wrap_pool_connect
    return fn()
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\pool.py", line 345, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\pool.py", line 788, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\pool.py", line 532, in checkout
    rec = pool._do_get()
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\pool.py", line 1284, in _do_get
    return self._create_connection()
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\pool.py", line 350, in _create_connection
    return _ConnectionRecord(self)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\pool.py", line 477, in __init__
    self.__connect(first_connect_check=True)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\pool.py", line 683, in __connect
    pool.dispatch.connect(self.connection, self)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\sqlalchemy\event\attr.py", line 246, in __call__
    fn(*args, **kw)
  File "D:\user.one\personal\_python\Anaconda3\lib\site-packages\chatterbot\storage\sql_storage.py", line 70, in set_sqlite_pragma
    dbapi_connection.execute('PRAGMA journal_mode=WAL')
AttributeError: 'MySQLConnection' object has no attribute 'execute'

However, upon commenting the chatterbot code, the error disappears. It seems like there is a problem with connecting underlying databases with sqlalchemy.

How do I solve this problem?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

6reactions
leandrohmvieiracommented, May 10, 2018

@mdalvi something like this

bot = ChatBot('mysqlbot',
                  storage_adapter="chatterbot.storage.SQLStorageAdapter",
                  database_uri="mysql://user:password@host:port/databasename",
               		)
2reactions
leandrohmvieiracommented, Apr 24, 2018

@mdalvi I’m having this issue too, looks like SQLite(chatterbot default storage is SQLite) and MySQL aren’t getting along well. To workaround this, i changed chatterbot storage to MySQL

Read more comments on GitHub >

github_iconTop Results From Across the Web

'MySQLConnection' object has no attribute 'execute' error on ...
Try it: import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword" ) query1 ...
Read more >
How to solve the attribute error 'MySQL' that has no ... - Quora
Python DB-API libraries like MySQLdb must have a [code ]connect()[/code] function, not a connector attribute. Make sure to import the right library name....
Read more >
How to fix 'MySQLConnection' object has no attribute ...
I get : AttributeError: 'MySQLConnection' object has no attribute 'escape_string'. I thought it's a bug related to the mysql_connector, so I thought updating ......
Read more >
10.5.4 MySQLCursor.execute() Method
This method executes the given database operation (query or command). ... The data values are converted as necessary from Python objects to something...
Read more >
AttributeError: 'Connection' object has no attribute '_execute'
line 132, in execute self._execute(cursor, query, parameters) AttributeError: 'Connection' object has no attribute '_execute' Any advice on how to fix this?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found