From webscraping with BeautifulSoup, I get a query string parameter that end up being represented as:
param_value = u'\xc3\xa9cosyst\xc3\xa8mes'
When reading it, I can guess that it should be represented as écosytèmes
I tried several way to encode / escape / decode (as described here and here)
But I keep on getting errors like:
UnicodeEncodeError('ascii', u'\xc3\xa9cosyst\xc3\xa8mes', 0, 2, 'ordinal not in range(128)')
I also tried the solution proposed as duplicate:
Python 2.7.15 (default, Jul 23 2018, 21:27:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> s = u'\xc3\xa9cosyst\xc3\xa8mes'
>>> s.encode('latin-1').decode('utf-8')
u'\xe9cosyst\xe8mes'
but it gets me back to square 1...
How can I get from u'\xc3\xa9cosyst\xc3\xa8mes'
to u'écosystèmes'
?