Sebastian Nielsen Sebastian Nielsen - 10 months ago 50
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 "", line 96
SyntaxError: Non-UTF-8 code starting with '\xe5' in file on line 96, but no encoding declared; see 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 Source

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'