Open bendavis78 opened 3 years ago
I ran into the same problem, but when using the filter
method. The workaround I found was to convert the string to latin-1
encoding.
Using where
:
display_name = 'Kimberly O’Neil'.encode('utf-8').decode('latin-1') # Kimberly OâNeil
search = f"DisplayName = '{display_name.replace("'", r"\'")}'"
result = objects.Customer.where(search, qb=client)
Using filter
(Useful if matching whole fields and can be build dynamically):
display_name = 'Kimberly O’Neil'.encode('utf-8').decode('latin-1')
search = {
'DisplayName': display_name
}
result = objects.Customer.filter(**search, qb=client)
You could also use json
to make the string safe, but I haven't tried that yet ([1:-1]
removes the double quotes):
display_name = json.dumps('Kimberly O’Neil')[1:-1] # Kimberly O\u2019Neil
Running the following line produces a
UnicodeEncodeError
:The apostrophe in the string is character code
U+2019 - RIGHT SINGLE QUOTATION MARK
Full exception below: