Franzech Domâs Franzech Domâs - 3 months ago 37
Python Question

Base.py: Unicode equal comparison failed to convert both arguments to Unicode in

I was taking a look to a couple of related questions which treats about the same issue, but I still don't find a way to solve it.

It turns out that every time I execute a Django-related command, it prints me out the expected output plus something like this:

/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py:307: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
return name == ":memory:" or "mode=memory" in force_text(name)


And here is the context of that line:

def is_in_memory_db(self, name):
return name == ":memory:" or "mode=memory" in force_text(name)


Despite the Django server works, it's kind of annoying having always this message printed out on my screen. So, why is this happening and how could this be solved?

Answer

use encode('utf-8') to make correct comparing:

name.encode('utf-8') == ":memory:" or "mode=memory" in force_text(name)

Use full info:

Unicode HOWTO

Solving Unicode Problems in Python 2.7

Comments