Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during Mongo adapter statement serialization #203

Closed
NotSoSuper opened this issue Jun 27, 2016 · 22 comments
Closed

Error during Mongo adapter statement serialization #203

NotSoSuper opened this issue Jun 27, 2016 · 22 comments

Comments

@NotSoSuper
Copy link

NotSoSuper commented Jun 27, 2016

Hey, after I started using the mongodb storage adapter, I keep getting this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/discord/ext/commands/bot.py", line 247, in _run_extra
    yield from coro(*args, **kwargs)
  File "./mods/AI.py", line 47, in on_message
    msg = "**{0}**\n".format(message.author.name)+str(chatbot.get_response(message.content))
  File "/usr/local/lib/python3.5/dist-packages/chatterbot/chatterbot.py", line 149, in get_response
    self.storage.update(input_statement)
  File "/usr/local/lib/python3.5/dist-packages/chatterbot/adapters/storage/mongodb.py", line 126, in update
    data = statement.serialize()
  File "/usr/local/lib/python3.5/dist-packages/chatterbot/conversation/statement.py", line 80, in serialize
    data["in_response_to"].append(response.serialize())
  File "/usr/local/lib/python3.5/dist-packages/chatterbot/conversation/statement.py", line 80, in serialize
    data["in_response_to"].append(response.serialize())
AttributeError: 'dict' object has no attribute 'serialize'
@gunthercox
Copy link
Owner

This sounds like an issue that may have been fixed in a recent release of ChatterBot, can you confirm what version you are using?

@NotSoSuper
Copy link
Author

I installed 2 weeks ago, I'll try pip upgrade, if nothing I'll update from the repo.

@NotSoSuper
Copy link
Author

NotSoSuper commented Jun 27, 2016

It seems as I was on the latest version, 0.4.3 but I've went ahead and uninstalled pip and installed from source. Hope the issue is fixed, closed for now.

@NotSoSuper NotSoSuper reopened this Jul 1, 2016
@NotSoSuper
Copy link
Author

Hey, I'm still getting it for some reason even after a full update,

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/discord/ext/commands/bot.py", line 247, in _run_extra
yield from coro(_args, *_kwargs)
File "./mods/AI.py", line 47, in on_message
msg = "{0}\n".format(message.author.name)+str(chatbot.get_response(message.content))
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.3-py3.5.egg/chatterbot/chatterbot.py", line 149, in get_response
self.storage.update(input_statement)
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.3-py3.5.egg/chatterbot/adapters/storage/mongodb.py", line 126, in update
data = statement.serialize()
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.3-py3.5.egg/chatterbot/conversation/statement.py", line 85, in serialize
data["in_response_to"].append(response.serialize())
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.3-py3.5.egg/chatterbot/conversation/statement.py", line 85, in serialize
data["in_response_to"].append(response.serialize())
AttributeError: 'dict' object has no attribute 'serialize'

@gunthercox
Copy link
Owner

Hi, I can't seem to replicate this issue. Can you post some more information to help me debug this:

  1. The parameters you are passing to the ChatBot() constructor.
  2. The version of python you are using.

@gunthercox gunthercox changed the title Error Error during Mongo adapter statement serialization Jul 2, 2016
@NotSoSuper
Copy link
Author

NotSoSuper commented Jul 2, 2016

Python version: 3.5

chatbot = ChatBot("NotSoBot",
    storage_adapter="chatterbot.adapters.storage.MongoDatabaseAdapter",
    logic_adapter="chatterbot.adapters.logic.ClosestMeaningAdapter",
    input_adapter="chatterbot.adapters.input.VariableInputTypeAdapter",
    output_adapter="chatterbot.adapters.output.OutputFormatAdapter",
    format='text',
    database='chatterbot-database',
    database_uri='mongodb://localhost:27017/')
chatbot.set_trainer(ChatterBotCorpusTrainer)
chatbot.train("chatterbot.corpus.english")

It works first time, few times actually but then for no reason starts to error. I receive it around 50 times and then no responses work until I reload it and it starts working again.

@gunthercox
Copy link
Owner

Alright, thank you. I will see if I can track down where this is happening.

@gunthercox
Copy link
Owner

@NotSoSuper Not sure if this is part of the issue, but I believe you may needs to specify output_format='text' instead of format='text' in your code. It appears this was incorrect in the documentation.

@NotSoSuper
Copy link
Author

Alright, testing it now, thanks for the update!

@NotSoSuper
Copy link
Author

Seems to be working good now, had a few testers. Thanks!

@NotSoSuper
Copy link
Author

and its back :(

@gunthercox
Copy link
Owner

Sorry about the long wait on this. I believe I have finally tracked down the source of the issue. It appears that in some cases, statement objects were being added to the response list of other statements. While this should have been Ok in theory since both objects share a similar API, it actually caused a problem during deserialization because some of the attributes remained in dictionary form. #224 should correct this issue.

@NotSoSuper
Copy link
Author

Just upgraded @gunthercox and it's back but in a new format,
`Traceback (most recent call last):
File "./mods/AI.py", line 51, in on_message
msg = "{0}\n".format(message.author.name)+str(chatbot.get_response(message.content))
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/chatterbot.py", line 149, in get_response
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/adapters/storage/mongodb.py", line 128, in update
data = statement.serialize()
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/conversation/statement.py", line 85, in serialize
def serialize(self):
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/conversation/statement.py", line 85, in serialize
def serialize(self):
AttributeError: 'dict' object has no attribute 'serialize'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/discord/ext/commands/bot.py", line 247, in _run_extra
yield from coro(_args, *_kwargs)
File "./mods/AI.py", line 54, in on_message
msg = "{0}\n".format(message.author.name)+str(chatbot.get_response(message.content))
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/chatterbot.py", line 149, in get_response
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/adapters/storage/mongodb.py", line 128, in update
data = statement.serialize()
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/conversation/statement.py", line 85, in serialize
def serialize(self):
File "/usr/local/lib/python3.5/dist-packages/ChatterBot-0.4.5-py3.5.egg/chatterbot/conversation/statement.py", line 85, in serialize
def serialize(self):
AttributeError: 'dict' object has no attribute 'serialize'`

sorry for all the issue this bug is causing :(

@gunthercox
Copy link
Owner

gunthercox commented Aug 9, 2016

@NotSoSuper I haven't created a new release on PyPy with the changes I made yet. Did you upgrade with pip or from the code on GitHub?

Also, its good that you are reporting the issue. It all helps to improve ChatterBot for everyone who uses it.

@gunthercox gunthercox reopened this Aug 9, 2016
@NotSoSuper
Copy link
Author

NotSoSuper commented Aug 9, 2016

I pulled from github and ran python3.5 setup.py install
It seems as the error is different as you made the serialize in a function now

@NotSoSuper
Copy link
Author

NotSoSuper commented Aug 9, 2016

You think wiping my mongodb for the data would work? I would rather not because I have a lot of data from users using it however I will if needed.

@gunthercox
Copy link
Owner

You could specify a different database name and your old data would be safe while you test your theory.

@NotSoSuper
Copy link
Author

yeah, that's what I was thinking. I'll try it when I get home, thanks.

@gunthercox
Copy link
Owner

@NotSoSuper Any success?

@NotSoSuper
Copy link
Author

Oh sorry, forgot to respond. After updating again with your new commits a few days later, I haven't received the error again. Everything seems well at this point and it's fast. Thanks for keeping in check and continuing development of this project!

@gunthercox
Copy link
Owner

Awesome, glad to hear!

@lock
Copy link

lock bot commented Mar 10, 2019

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.

@lock lock bot locked and limited conversation to collaborators Mar 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants