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

Issue 386: LookupError: unknown encoding: utf8mb3 #406

Closed
wants to merge 13 commits into from

Conversation

Samira-El
Copy link
Contributor

@Samira-El Samira-El commented Jul 4, 2023

Issue: #386

For databases/tables that use utf8mb3, row events cannot be parse and fail with LookupError: unknown encoding: utf8mb3 because pymysql has no charset utf8mb3.

def __read_string(self, size, column):

Traceback (most recent call last):
  File "/home/github/python-mysql-replication/examples/mariadb_gtid/read_event.py", line 82, in <module>
    binlogevent.dump()
  File "/home/github/python-mysql-replication/pymysqlreplication/event.py", line 45, in dump
    self._dump()
  File "/home/github/python-mysql-replication/pymysqlreplication/row_event.py", line 526, in _dump
    super(WriteRowsEvent, self)._dump()
  File "/home/github/python-mysql-replication/pymysqlreplication/row_event.py", line 460, in _dump
    print("Changed rows: %d" % (len(self.rows)))
  File "/home/github/python-mysql-replication/pymysqlreplication/row_event.py", line 474, in rows
    self._fetch_rows()
  File "/home/github/python-mysql-replication/pymysqlreplication/row_event.py", line 469, in _fetch_rows
    self.__rows.append(self._fetch_one_row())
  File "/home/github/python-mysql-replication/pymysqlreplication/row_event.py", line 522, in _fetch_one_row
    row["values"] = self._read_column_data(self.columns_present_bitmap)
  File "/home/github/python-mysql-replication/pymysqlreplication/row_event.py", line 157, in _read_column_data
    values[name] = self.__read_string(1, column)
  File "/home/github/python-mysql-replication/pymysqlreplication/row_event.py", line 265, in __read_string
    string = string.decode(encoding, decode_errors)
LookupError: unknown encoding: utf8mb3

I'm proposing this fix that intercepts the charset and changes it to utf8 if it's utf8mb3.
In Mariadb and Mysql utf8 is an alias for utf8mb3, and mysql has deprecated utf8mb3 and recommends using utf8mb4.

@Samira-El Samira-El changed the title LookupError: unknown encoding: utf8mb3 Issue 386: LookupError: unknown encoding: utf8mb3 Jul 4, 2023
@Samira-El
Copy link
Contributor Author

Hi @julien-duponchelle,

Can you take a look at this potential fix please?

@Samira-El
Copy link
Contributor Author

Another solution would be to bump pymysql to v1.1.0 which now has support for utfmb3
https://github.com/PyMySQL/PyMySQL/blob/main/CHANGELOG.md#v110

@julien-duponchelle
Copy link
Owner

@Samira-El can you confirm that we can bump to v1.1.0 of PyMySQL ? It sound a more clean idea

Thanks a lot for the help

@Samira-El
Copy link
Contributor Author

Hi, we're running PyMySQL v1.1.0 and mysql-replication v0.40 in production against Mariadb instances and we're no longer running into this issue.

@julien-duponchelle
Copy link
Owner

Thanks I did a new release with the version of PyMYSQL changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants