cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Not a customer? Start a free trial

Click the Start a free trial link to start a 15-day SaaS trial of our product and join our community as a trial user. If you are an existing customer do not start a free trial.

AppDynamics customers and established members should click the sign in button to authenticate.

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

Character encoding for synthetic Python scripts

Jonathan.Sanders
Explorer

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?

By replying you agree to the Terms and Conditions of the AppDynamics Community.
Character encoding for synthetic Python scripts
4 REPLIES 4
Abhimanyu.Arora
AppDynamics Team

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.
Jonathan.Sanders
Explorer

Re: Character encoding for synthetic Python scripts

Unfortunately that doesn’t fix the issue.
Abhimanyu.Arora
AppDynamics Team

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.
Jonathan.Sanders
Explorer

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