This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Unexpected error occurred. UnicodeEncodeError: 'ascii' codec can't encode character u'\xd3' in position 21: ordinal not in range(128)

Hi,

I monitor some apaches whit templates for agent and work, but one day show the next error in all templates: "Unexpected error occurred. UnicodeEncodeError: 'ascii' codec can't encode character u'\xd3' in position 21: ordinal not in range(128)"

pastedImage_0.png

pastedImage_4.png

The version Orion is 2017.3 SAM 6.4

Does anyone know how to solve it? emoticons_sad.png

Please?

  • Looks like there was another post from four months ago that went unanswered:

    UnicodeEncodeError - Linux Script

    If it were me I would start with turning on debugging for the Application Template and review the logs, depending on what I'm seeing, the criticality of the issue and how many nodes are affected I might reach out to Support as well.

    Here's how to enable the debugging and review the logs:

    Success Center

  • Hi jrouviere,

    The log debug in the agent show this lines:

    19/06/14 15:34:06.663 PID: 22652 TID: 140264761460480 [ERROR] job_monitor - Traceback (most recent call last):

      File "job_monitor.py", line 62, in <module>

        result = execute(simplejson.loads(job_configuration), job_credential)

      File "job_monitor.py", line 50, in execute

    probe_result = probe_helper.run_probe(description, job_cache, probe_credentials)

      File "/opt/SolarWinds/Agent/bin/Plugins/APM/probe_helper.py", line 55, in run_probe

    probe_result = method(description, job_cache, probe_credentials)

      File "/opt/SolarWinds/Agent/bin/Plugins/APM/probes/LinuxScriptProbe.py", line 91, in run_probe

    script_body = apply_macros(script_body, config, probe_detail, column_definitions, credentials)

      File "/opt/SolarWinds/Agent/bin/Plugins/APM/probes/LinuxScriptProbe.py", line 82, in apply_macros

        result = result.replace('${%s}' % key, str(value))

    UnicodeEncodeError: 'ascii' codec can't encode character u'\xd3' in position 21: ordinal not in range(128)

    The template is config for agent.

    the strange thing is that from one moment to another the templates stopped working. All in same time. I not change nothing. emoticons_sad.png

    The ploblem in this moment the app not support. I was recently given the system. emoticons_sad.png

  • Unfortunately the application template I have is using Perl scripts and your errors indicate an issue in Python which leads me to believe it might be agent related. You could try to change the Preferred Polling Method to Agentless under the Advanced settings (when editing the application template) as a work around, but I don't have ready access to an agent to dig into what that script would be doing to help more directly than that.

    More information:

    Success Center

  • Hi everybody,

    in this moment the app work, i realized the next activities:

    1. Create backup for the file /opt/SolarWinds/Agent/bin/Plugins/APM/probes/LinuxScriptProbe.py

    2. Edit line 82:

              result = result.replace('${%s}' % key, str(value))

         Change for:

              result = result.replace('${%s}' % key, unicode(value))

    3. Restart the agent:

    /etc/init.d/swiagentd restart

    In this moment the agent work good. I see in this week how app functionate.

  • Try setting the system default encoding as utf-8 at the start of the script, so that all strings are encoded using that.

    Example -

    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')

    The above should set the default encoding as utf-8 .

    In most cases, the issue is that when you call str(), python uses the default character encoding to try and encode the bytes you gave it, which in your case are sometimes representations of unicode characters. To fix the problem, you have to tell python how to deal with the string you give it by using .encode('whatever_unicode'). Most of the time, you should be fine using utf-8. So, stop using str() to convert from unicode to encoded text / bytes, properly use .encode() to encode the string:,

    yourstring.encode('utf-8')

    For python 3.x ,there is default encoding, hence there will be no issue of encoding.