Dynamic Languages (Node.JS, Python, PHP, C/C++, Webserver Agent)

cancel
Showing results for 
Search instead for 
Did you mean: 

Character encoding for synthetic Python scripts

Character encoding for synthetic Python scripts

I have a synthetic script running on App Dynamics which asserts that the title of the page contains the non-Ascii character 'EN DASH'. The script runs fine on App Dynamics, but when I copy the script locally Python attempts to decode the character using Ascii and throws the following error:

 

SyntaxError: Non-ASCII character '\xe2' in file my-script.py on line 24, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

 

I've tried forcing Python to use UTF-8 encoding by including the following at the top of the script:

 

# coding=utf-8
 
...but I then see the following error.
 

 

File "scripts/halo-privacy-center.py", line 25, in <module>

    assert "Tesco – Privacy Centre" in driver.title

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 6: ordinal not in range(128)

 

Where can I find information on how the environment for Python is configured for App Dynamics so I can replicate that locally? Or in other words, how can I force Python to decode characters in the same way it does in App Dynamics?

Character encoding for synthetic Python scripts
4 REPLIES 4

Re: Character encoding for synthetic Python scripts

Hi Jonathan,

 

May be you can try adding terminal encoding where you are trying to run the python script -

export LC_CTYPE=en_US.UTF-8

 

See if this resolves the issue.

 

Thanks

Abhimanyu



Found something helpful? Click the Accept as Solution button to help others find answers faster.
Liked something? Click the Thumbs Up button.

Re: Character encoding for synthetic Python scripts

Unfortunately that doesn’t fix the issue.

Re: Character encoding for synthetic Python scripts

Hi Jonathan,

 

Can you provide a sample script that would produce this error, so that I can try it on my environment and update you with a potential solution.

 

Thanks

Abhimanyu



Found something helpful? Click the Accept as Solution button to help others find answers faster.
Liked something? Click the Thumbs Up button.

Re: Character encoding for synthetic Python scripts

This is a simplified version of my script:

 

 

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
driver.get(https://www.google.com")
assert "Page title – with strange hyphen" in driver.title
driver.quit