I am developing a cross-platform script on a Windows 7, Python 2.7 computer. The script will be also used on a MacOSX computer with Python 2.7 installed.
The following script is working perfectly on my Windows computer, however when I run it on the Mac, I get a unicode error.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import webbrowser
webbrowser.open(u"http://www.google.fr?q=testéè")
Here is the error:
Mac-mini-de-paul:paul paul$ python testUnicode.py
Traceback (most recent call last):
File "testUnicode.py", line 6, in <module>
webbrowser.open(u"http://www.google.fr?q=testéè")
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/webbrowser.py", line 62, in open
if browser.open(url, new, autoraise):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/webbrowser.py", line 637, in open
osapipe.write(script)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 42-43: ordinal not in range(128)
I don't really understand what's the problem here, Python's base functions are supposed to deal properly with unicode filenames, aren't they?
Note: I saw this question, but it did not help me and the OP is not having any error: IMO not a duplicate