Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError: 'charmap' codec can't encode characters in position 6-19: character maps to <undefined> #11

Open
nmz787 opened this issue Sep 26, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@nmz787
Copy link

nmz787 commented Sep 26, 2019

Describe the bug

Traceback (most recent call last):
  File "dflauncher.py", line 242, in <module>
    automate_script(3)
  File "dflauncher.py", line 167, in automate_script
    'Username:'], timeout=4)
  File "C:\Users\myusername\git\test\wexpect.py", line 1366, in expect
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "C:\Users\myusername\git\test\wexpect.py", line 1380, in expect_list
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "C:\Users\myusername\git\test\wexpect.py", line 1433, in expect_loop
    c = self.read_nonblocking(self.maxread, timeout)
  File "C:\Users\myusername\git\test\wexpect.py", line 1793, in read_nonblocking
    self.logfile_read.write (s)
  File "C:\Python36\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 6-19: character maps to <undefined>

To Reproduce
I've got no clue... use a colon in the expectation?

Expected behavior
Not crash.

Environment:

  • [windows version] 10
  • [Python version] 3.6
  • [wexpect version] latest from pypi source, v2.3.6
@raczben raczben added the bug Something isn't working label Sep 26, 2019
@raczben raczben self-assigned this Sep 26, 2019
@raczben
Copy link
Owner

raczben commented Sep 26, 2019

At the first sight it seems that the logging fails. Please try to remove the logging from the line 1793 as a workaround.

I will try to reproduce as soon as it is possible.

@raczben
Copy link
Owner

raczben commented Sep 29, 2019

Here is a related StackOverflow post.

I have created a new branch: i11 for this issue.

unicode_parent can reproduce a very similar issue.

@nmz787
Copy link
Author

nmz787 commented Nov 5, 2019

I just encountered the error again.
For me it was self.logfile_read, not self.logfile... I applied what the stackoverflow post said, changing the wexpect.py line to:
self.logfile_read.write (s.encode("utf-8"))

and things seem to work now :)

@nmz787
Copy link
Author

nmz787 commented Mar 3, 2020

I had to update my local copy of wexpect.py with this line today, in place of the previous "fix":
self.logfile_read.write (s.encode("utf-8") if not isinstance(s, str) else s)
It was after using this line:

shell.logfile_read = sys.stdout

that I got the strange error:

Traceback (most recent call last):
  File "main.py", line 11, in <module>
    shell.expect(unique_prompt)
  File "C:\Users\nmz787\git\wexpect_issues\wexpect.py", line 1388, in expect
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "C:\Users\nmz787\git\wexpect_issues\wexpect.py", line 1402, in expect_list
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "C:\Users\nmz787\git\wexpect_issues\wexpect.py", line 1455, in expect_loop
    c = self.read_nonblocking(self.maxread, timeout)
  File "C:\Users\nmz787\git\wexpect_issues\wexpect.py", line 1816, in read_nonblocking
    self.logfile_read.write (s.encode("utf-8") if isinstance(s, str) else s)
TypeError: write() argument must be str, not bytes

@raczben
Copy link
Owner

raczben commented Feb 1, 2021

I beleive this is the same as #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants