I get a UnicodeDecodeError in mecab-python3

I wanted to escape from the Unicode problem, so I chose Python3, but I get a UnicodeDecodeError because mecab-python3 is not working properly.

Moreover, when you run the test, it appears randomly

Case study

import MeCab
mecab = MeCab.Tagger()
node = mecab.parseToNode("Of the thighs and thighs")
while node:
    print(node.surface)
    node = node.next

Then

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-11-1f88b1ec9c08> in <module>()
      1 while node:
----> 2     print(node.surface)
      3     node = node.next

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 0: invalid start byte

The error is ...

How to cure

It's hard to cure, so it's said to do mecab.parse ("") first.

import MeCab
mecab = MeCab.Tagger()
mecab.parse("")  #add to
node = mecab.parseToNode("Of the thighs and thighs")
while node:
    print(node.surface)
    node = node.next

Then

Plum
Also
Peaches
Also
Peaches
of
home

did it. I'm not sure, but it started working.

Recommended Posts

I get a UnicodeDecodeError in mecab-python3
I get a KeyError in pyclustering.xmeans
When I get a chromedriver error in Selenium
I get a UnicodeDecodeError when running with mod_wsgi
I get a java.util.regex.PatternSyntaxException when splitting a string in PySpark
I tried "How to get a method decorated in Python"
I wrote a script to get a popular site in Japan
Get a Boolean in Flask's request
I get a can't set attribute when using @property in python
I want to print in a comprehension
I made a payroll program in Python!
How to get a stacktrace in python
I can't get the element in Selenium!
Get a token for conoha in python
I started Node.js in a virtual environment
I created a password tool in Python.
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
[Python] Get the files in a folder with Python
A memo that I wrote a quicksort in Python
Get the caller of a function in Python
I want to create a window in Python
I tried playing a typing game in Python
I wrote a class in Python3 and Java
[Memo] I tried a pivot table in Python
Get only the subclass elements in a list
Get a panoramic image in Google Street View
I wrote a design pattern in kotlin Prototype
I tried adding a Python3 module in C
Get a glimpse of machine learning in Python
[PyTorch] I was a little lost in torch.max ()
I made a tool to get new articles
I wrote a Japanese parser in Japanese using pyparsing.
I made a Caesar cryptographic program in Python.
Get a row containing a specific element in np.where
In the Chainer tutorial, I get an error when importing a package. (mock)
I was in vain because I couldn't get a send parent order with pybitflyer
I get a strange window when I use the open directory dialog in Tkinter
Draw a graph in Julia ... I tried a little analysis
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I made a prime number generation program in Python
〇✕ I made a game
Get the file name in a folder using glob
I wrote a design pattern in kotlin Factory edition
I want to transition with a button in flask
I get an Import Error in Python Beautiful Soup
I wrote a design pattern in kotlin Builder edition
I want to use a python data source in Re: Dash to get query results
I want to write in Python! (2) Let's write a test
I wrote a design pattern in kotlin Singleton edition
UnicodeDecodeError in pandas read_csv
I wrote a design pattern in kotlin Adapter edition
I made a script to put a snippet in README.md
I tried to implement a pseudo pachislot in Python
I wrote a design pattern in kotlin, Iterator edition
I got a UnicodeDecodeError when pip install on ubuntu
I want to randomly sample a file in Python
I get an error when I put opencv in pyautoGUI
dict in dict Makes a dict a dict
I want to work with a robot in python.
BigQuery-If you get a Reason: responseTooLarge error in Python