UnicodeWarning: Unicode-Gleichheitsvergleich konnte beide Argumente nicht in Unicode konvertieren
Ich kenne viele Leute, die auf diesen Fehler gestoßen sind, aber ich konnte keine Lösung für mein Problem finden.
Ich habe eine URL, die ich normalisieren möchte:
url = u"http://www.dgzfp.de/Dienste/Fachbeitr%C3%A4ge.aspx?EntryId=267&Page=5"
scheme, host_port, path, query, fragment = urlsplit(url)
path = urllib.unquote(path)
path = urllib.quote(path,safe="%/")
Dies gibt eine Fehlermeldung aus:
/usr/lib64/python2.6/urllib.py:1236: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
res = map(safe_map.__getitem__, s)
Traceback (most recent call last):
File "url_normalization.py", line 246, in <module>
logging.info(get_canonical_url(url))
File "url_normalization.py", line 102, in get_canonical_url
path = urllib.quote(path,safe="%/")
File "/usr/lib64/python2.6/urllib.py", line 1236, in quote
res = map(safe_map.__getitem__, s)
KeyError: u'\xc3'
Ich habe versucht, den Unicode-Indikator "u" aus der URL-Zeichenfolge zu entfernen und erhalte keine Fehlermeldung. Aber wie kann ich den Unicode automatisch loswerden, weil ich ihn direkt aus einer Datenbank les