Python 3.4.0에서 pexpect 모듈 (버전 3.3)을 사용하려고합니다. child.expect 메서드를 호출하면 오류가 발생합니다.Python 3에서 pexpect 모듈의 expect 메소드를 호출 할 때 TypeError가 발생했습니다.
TypeError: must be str, not bytes
child = pexpect.spawn('ssh [email protected]')
index = child.expect([pexpect.TIMEOUT, pexpect.EOF, ssh_newkey, '.*password:'])
가 정확히 동일한 코드가 pexpect 모듈 (버전 3.1), 파이썬 버전 2.7.6 제대로 작동합니다
실제 코드는 pexpect 문서에서 표준 예입니다.
pitpect 버전 3.3에는 Python 2.6 또는 3.2 이상이 필요하다는 GitHub의 Pexpect 설명서가 나와 있습니다. 이 모듈의 문서에 언급 된 내용에도 불구하고 pexpect가 Python 3에서 작동하지 않는다는 것을 아는 사람이 있습니까?
Traceback (most recent call last):
File "/home/sambo9/python/python3-pexpect.py", line 17, in <module>
main()
File "/home/sambo9/python/python3-pexpect.py", line 13, in main
child.expect('.*password:')
File "/usr/local/lib/python3.4/dist-packages/pexpect/__init__.py", line 1451, in expect
timeout, searchwindowsize)
File "/usr/local/lib/python3.4/dist-packages/pexpect/__init__.py", line 1466, in expect_list
timeout, searchwindowsize)
File "/usr/local/lib/python3.4/dist-packages/pexpect/__init__.py", line 1535, in expect_loop
c = self.read_nonblocking(self.maxread, timeout)
File "/usr/local/lib/python3.4/dist-packages/pexpect/__init__.py", line 985, in read_nonblocking
self._log(s, 'read')
File "/usr/local/lib/python3.4/dist-packages/pexpect/__init__.py", line 908, in _log
second_log.write(s)
File "/usr/lib/python3.4/idlelib/PyShell.py", line 1339, in write
raise TypeError('must be str, not ' + type(s).__name__)
TypeError: must be str, not bytes
또한, 나는 또한 내가 스크립트를 실행할 때 암호를 입력하라는 메시지가 우분투 GUI를 통해 공개 "OpenSSH를"상자 팝업을 참조하십시오
이것은 내가 얻을 추적 출력입니다. 이것은 Python 2.7.6에서는 발생하지 않습니다. 파이썬 2.7에서는 수동 조작없이 시스템에 로그인 할 수 있습니다. 모든 것은 스크립트를 통해 자동으로 이루어집니다. documentation에서
역 추적 도움이 될 것입니다. – ThiefMaster
python3에서 strings/bytes 구분과 관련이있을 수 있습니다. 도움이된다면 [this] (http://stackoverflow.com/a/606199/3586654) 답변을 참조하십시오. – vikramls
@ThiefMaster 예상 메서드 호출 후 추적 출력이 있습니다 : – sambo9