0

First I was getting an error 'UnicodeDecodeError: 'charmap' codec can't decode byte 0x81' and it seemed like data was getting trained for first three files and error crept on fourth file when I checked the folder a new file was created at fourth spot 'dsqlite3' and some other pickle file.I have a doubt that because of the creation of these files in the folder code is giving an error of 'unicodedecodeerror'. But now the code is giving a different error"FileNotFoundError: [Errno 2] No such file or directory: 'ai.yml'" Please share your insights. '

I think maybe I am making a mistake in the code.

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os


bot= ChatBot("Bot")

trainer = ListTrainer(bot)

for files in os.listdir(r"C:/Users/sachin/Desktop/Pythonfiles/Chatbot/chatterbot-corpus-master/chatterbot_corpus/data/english"):
    data=open(files,"r").readlines()
    trainer.train(data)

while True:
    message=input('You :')
    if message.strip()!= 'Bye':
        reply=bot.get_response(message)
        print('Chatbot',reply)
    if message.strip()=='Bye':
        print('ChatBot: Bye')
        break
DearBeliever
  • 41
  • 1
  • 7

1 Answers1

0

Your code can't decode one of the files because it's not encoded in unicode. 0x81 is a control character in unicode. Here's a good resource on this type of error and how to deal with it.

The File not found error is because one of the files in that directory can't be found. The files you are listing are not the full path to those files. You need to use:

"C:/Users/sachin/Desktop/Pythonfiles/Chatbot/chatterbot-corpus-master/chatterbot_corpus/data/english/{}".format(files)

in your open call.

jacob
  • 398
  • 4
  • 13
  • thanks for your answer but now it is giving a previous error'UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 3313: character maps to ',Would you care to help? – DearBeliever Jul 10 '19 at 17:52
  • It's hard to say without knowing what file you're trying to decode. The error is saying that the file you're decoding has characters that can't be decoded to unicode. Like I said, 0x81 does not map to anything in utf-8 unicode. It's likely that there is a problem in the file you are trying to decode. – jacob Jul 10 '19 at 20:23