Sebastian Nielsen Sebastian Nielsen - 14 days ago 10
Python Question

Unable to run script because of the 'å's presence in my script

Here is the line that causes the error:

emner = browser.find_element_by_link_text('Armbåndsure og lommeure')


And the output:

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


I need to have this "å" in my script there is no way around it, I cant replace it. How do I "allow" it to be in my script. I know its something about unicode, but I dont know that much about it. So I thought a kind person would help me out here on stack overflow.

Thanks in advance!

Answer

You have saved your file in a non-UTF8 encoding, but Python interprets files as UTF8-encoded by default.

Either save the file as UTF8 from whatever text editor you are using, or add the line # coding: latin-1 as the first or second line in your file.

If you are unable to do either, you can replace the non-ASCII text with an ASCII-only escape sequence: 'Armb\xe5ndsure og lommeure'

Comments