Reputation: 4209
Using python 3.5, as seen here: link. The image shows what keeps happening when I try to run ANY script that isn't executed inside PyCharm. If I run the exact same code inside PyCharm it works perfectly fine. Here is the code I ran in cmd:
python test.py
Error message:
File "test.py", line 86
SyntaxError: Non-UTF-8 code starting with '\xf8' in file test.py on line 86, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
I figured out that it was because I had some "Not English letters" (such as æ, ø, å). But the problem is the script shall search for a web element with the text "armbåndsure"
. It won't recognize the å -character, how do I fix this error? Here is my code:
emner = browser.find_element_by_link_text('Armbåndsure og lommeure')
The error code of that line :
File "test.py", line 96
SyntaxError: Non-UTF-8 code starting with '\xe5' in file test.py on line 96, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Upvotes: 4
Views: 754
Reputation: 12900
At this point any time you say "my script doesnt even have anything to do with unicode" you are almost certainly wrong. Your code file is most likely saved as UTF-8 therefore making your script itself unicode and non-English characters should work assuming they are all encoded right. If you haven't already, you should read the Python docs on unicode support (python 2x, Python 3x).
Since you say the script runs in PyCharm, likely it is detecting and setting the encoding properly but in other contexts the interpter is guessing incorrectly.
If you can get the file open in a good code editor with all characters appearing, try saving the file explicitly as UTF-8 and see if that corrects the encoding errors. Depending on your Python version you may also need to set the encoding explicitly in your file.
Upvotes: 1