简体   繁体   中英

AttributeError using python module py3270

As a part of some automation I am trying to connect to mainframe using python, where I can access the mainframe files and create a report. Just like using mainframe files as DB for python program.

To login to mainframe - we need to provide host details(xyz.host.com) followed with region details(h123p) and then with our credentials.

I found that we can do this using python package py3270 and tried doing it but getting the error.

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()

The error:

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'

Based on the error messages you're seeing, I suspect you're having a problem with missing/not found x3270/s3270 libraries.

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)

The above suggests that the library is trying to start Ws3270, the windows version of x3270, and is unable to do so.

Make sure the the required libraries are in your path and visible from python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM