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

Created on 16 Apr 2018  路  6Comments  路  Source: gunthercox/ChatterBot

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?

Most helpful comment

@mdalvi something like this

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

All 6 comments

which version chatterbot are you using? To know chatterbot version python -m chatterbot --version.

If you are using older version try to upgrade to latest version pip install --upgrade chatterbot

@vkosuri
python -m chatterbot --version = 0.8.5

@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

@leandrohmvieira

To workaround this, i changed chatterbot storage to MySQL

And how do we do that?

@mdalvi something like this

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

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ArunSingh1 picture ArunSingh1  路  3Comments

AmusingThrone picture AmusingThrone  路  3Comments

thedp picture thedp  路  4Comments

yuvalBor picture yuvalBor  路  3Comments

proguy627 picture proguy627  路  3Comments