question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeEncodeError write error in session_log (when unicode data is read in and then written to the session_log)

See original GitHub issue

Hi @ktbyers

Not sure why but some or my older scripts are running into UnicodeEncodeError : “‘ascii’ codec can’t encode character ‘\xe3’ in position 45774: ordinal not in range(128)”. Snippet of code below

`deviceinfo = {‘device_type’: ‘cisco_wlc’, ‘ip’: wlcipadd, ‘username’: username, ‘password’: password, ‘banner_timeout’: 16, ‘global_delay_factor’: 4, ‘session_log’:filename}

device = netmiko.ConnectHandler(**deviceinfo)

op = device.send_command_timing(“show ap summary”, use_textfsm=False)`

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rb3123commented, Sep 11, 2020

Hi @ktbyers

It seems our jump server was moved to a different data center pushing latency towards some WLC into 180 - 230ms zone. As netmiko has to fetch data over multiple iterations, some characters get malformed and fail to write into session logs on Windows (haven’t tested yet on Linux). This failure to write session log also causes entire driver to crash, terminating connection to WLC/switch. I have disabled session_log on driver level which has fixed the issue for us.

0reactions
ktbyerscommented, Dec 4, 2020

Naah, it clearly looks like a unicode write error:

File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 444, in _write_session_log
self.session_log.write(self.normalize_linefeeds(data))
UnicodeEncodeError: 'ascii' codec can't encode character '\u056e' in position 53: ordinal not in range(128)

i.e. there is unicode in the output of what is read back in and we are trying to write that out to the session_log. You probably could modify that behavior such that it writes out unicode (or strips unicode).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: Can't write to file - UnicodeEncodeError - Stack Overflow
To write Unicode text to a file, you could use io.open() function: #!/usr/bin/env python from io import open with open('utf8.txt', 'w', ...
Read more >
Overcoming frustration: Correctly using unicode in python2
In python, the unicode type stores an abstract sequence of code points. ... but throw an error when you give it a string...
Read more >
TT_11195 error in session log when running PowerCenter ...
This error occurs when the data contains extended ASCII or Unicode characters but one or more of the following are not configured:.
Read more >
Python JSON Encode Unicode and non-Ascii characters as-is
In this example, we will try to encode the Unicode Data into JSON. This solution is useful when you want to dump Unicode...
Read more >
Understanding Python unicode, str, UnicodeEncodeError and ...
Understanding the basics of Python 'unicode' and 'str' type; Deliberately causing UnicodeEncodeError and UnicodeDecodeError and fixing it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found