作为一些自动化的一部分,我试图使用python连接大型机,在这里我可以访问大型机文件并创建一个 报告。就像将大型机文件用作python程序的数据库一样。
要登录大型机-我们需要提供主机详细信息(xyz.host.com) 接下来是区域详细信息(h123p),然后是我们的凭据。
我发现我们可以使用python包py3270进行此操作,并尝试执行此操作但出现错误。
from py3270 import Emulator
# or not (uses s3270)
em = Emulator()
em.connect('xyx.example.com')
em.fill_field(3, 1, 'xxxx',5)
em.send_enter()
em.fill_field(2, 1, 'xxxxxxx', 7)
em.send_enter()
em.fill_field(8, 20, 'xxxxxxxx', 8)
em.send_enter()
# if your host unlocks the keyboard before truly being ready you can use:
em.wait_for_field()
# maybe look for a status message
if not em.string_found(1, 2, 'login succesful'):
abort()
# do something useful
# disconnect from host and kill subprocess
em.terminate()
错误:
File "C:/Users/vganr/PycharmProjects/test/mainframe.py", line 6, in
<module>
em = Emulator()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 273, in __init__
self.app = app or self.create_app(visible, args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 291, in create_app
return Ws3270App(args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 140, in __init__
self.spawn_app()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 145, in spawn_app
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 775,
in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 1178,
in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Exception ignored in: <function Emulator.__del__ at 0x038CB810>
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 285, in __del__
self.terminate()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 320, in terminate
if not self.is_terminated:
AttributeError: 'Emulator' object has no attribute 'is_terminated'
答案 0 :(得分:0)
根据您看到的错误消息,我怀疑您是缺少x3270 / s3270库的问题。
return Ws3270App(args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 140, in __init__
self.spawn_app()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 145, in spawn_app
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 775,
in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 1178,
in _execute_child
startupinfo)
以上内容表明该库正在尝试启动Windows版本x3270 Ws3270,但无法启动。
确保所需的库在您的路径中并且可以从python看到。