AttributeError using python module py3270 - python

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.

Related

jupyter nbconvert to PDF raises PermissionError: [WinError 5]

I'm trying to convert a Jupyter notebook into a PDF file but I keep getting the following error:
[NbConvertApp] Converting notebook ejercicios.ipynb to pdf
Traceback (most recent call last):
...
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\exporters\exporter.py", line 143, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\exporters\exporter.py", line 318, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\base.py", line 47, in __call__
return self.preprocess(nb, resources)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\base.py", line 69, in preprocess
nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\convertfigures.py", line 45, in preprocess_cell
output.data[self.to_format] = self.convert_figure(
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 125, in convert_figure
shell = self.command.format(from_filename=input_filename,
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
return self.get(obj, cls)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 538, in get
default = obj.trait_defaults(self.name)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
return self._get_trait_default_generator(names[0])(self)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
return self.func(*args, **kwargs)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 77, in _command_default
major_verison = self.inkscape_version.split('.')[0]
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
return self.get(obj, cls)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 538, in get
default = obj.trait_defaults(self.name)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 1578, in trait_defaults
return self._get_trait_default_generator(names[0])(self)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
return self.func(*args, **kwargs)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 57, in _inkscape_version_default
p = subprocess.Popen([self.inkscape, '--version'],
File "c:\users\netoo\appdata\local\programs\python\python38\lib\subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "c:\users\netoo\appdata\local\programs\python\python38\lib\subprocess.py", line 1311, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Acceso denegado
Looks like the default permissions for that command aren't enough to create a process of Inkscape, but I'm already using the command line with administrator privileges.
I was able to convert a notebook to PDF successfully past year, it's the same machine but I was using another version of Python, 3.6 or 3.7, does that have to do to with this?
I reported this issue here https://github.com/jupyter/nbconvert/issues/1525
My temporary solution was to use the absolute path as a string literal where I installed Inkscape instead of calling self.inkscape, in my case the path is 'C:\\Program Files\\Inkscape\\inkscape.exe':
https://github.com/jupyter/nbconvert/blob/88baf7a9ca724d74c9f890a60d5c3680e8959a14/nbconvert/preprocessors/svg2pdf.py#L57
in that line I have p = subprocess.Popen(['C:\\Program Files\\Inkscape\\inkscape.exe', '--version'].
I printed self.inkscape and the output was 'C:\Program Files\Inkscape\inkscape.exe'. I thought it was because of the double back slash so I tried os.path.abspath(self.inkscape) but it was adding the current path from where I'm calling the command at the beginning. I also tried pathlib.Path(self.inkscape) but it didn't work, so I have no idea what the problem could be.

VSCode Python debugging - permission issues

I am developing a small usb application using python (pyUSB) under Win 10 and have the following problem.
When I test basic commands under the python console, everything works fine. I can open the device, write bytes to it and read from it.
Next, I am trying to put it all in one tkinter app and debug it using VSCode. Here I keep getting the following error:
File "c:\Test\usbtester\main.py", line 198, in usb_open
self.dev.set_configuration()
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\core.py", line 869, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\core.py", line 147, in managed_set_configuration
self.managed_open()
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\core.py", line 120, in managed_open
self.handle = self.backend.open_device(self.dev)
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\backend\libusb1.py", line 787, in open_device
return _DeviceHandle(dev)
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\backend\libusb1.py", line 644, in __init__
_check(_lib.libusb_open(self.devid, byref(self.handle)))
File "c:\Program Files\Python37\usbtenv\lib\site-packages\usb\backend\libusb1.py", line 596, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
Can someone suggest what I could be doing wrong here?

The system cannot find the file specified (Python 3)

I'm trying read texts from an image using pytesseract but it throws this error no matter what I try.
Code:
import os
import subprocess
import pytesseract
from PIL import Image
subprocess.call('dir', shell=True)
print(os.path.isfile("test.jpg")) #True
im = Image.open("test.jpg")
text = pytesseract.image_to_string(im)
OUTPUT:
Traceback (most recent call last):
File "F:/Programming/PYTHON/captcha/test/main.py", line 10, in <module>
text = pytesseract.image_to_string(im)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 193, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 111, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "F:\Program Files (64bit)\Python\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "F:\Program Files (64bit)\Python\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Process finished with exit code 1
what's wrong? I know that file is there. I checked it using os.path.isfile and subprocess call
Other things that I tried:
-added full image file path using string literal 'r'
-tried different images and file types

Psychopy gives the ffmpeg error and does not play the videos

I want to create an experiment with Psychopy in which I will present randomly video that participant will have to evaluate.
I have created a routine with my MovieStim and my Rating response and a Loop with my conditions file (in which are my video files videoname.wmv).
All my videos are in the same folder as my experiment.
I have specified the MovieStim with a variable refering to my Loop's column ($Stimulus).
But when I run the experiment I have this message.
Running: E:\Thèse ESPRIT\Approach_Aversion\Experience_AA\Approach_Aversion_lastrun.py
pyo version 0.8.0 (uses single precision)
WARNING:root:Warning: could not find imageio's ffmpeg executable:
[Error 5] Accès refus: 'C:\\Program Files (x86)\\PsychoPy2\\lib\\site-packages\\imageio\\resources\\ffmpeg\\ffmpeg.win32.exe'
Traceback (most recent call last):
File "E:\Thèse ESPRIT\Approach_Aversion\Experience_AA\Approach_Aversion_lastrun.py", line 105, in <module>
depth=0.0,
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\contrib\lazy_import.py", line 120, in __call__
return obj(*args, **kwargs)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\movie3.py", line 124, in __init__
self.loadMovie(self.filename)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\movie3.py", line 170, in loadMovie
self._mov = VideoFileClip(filename, audio=(1 - self.noAudio))
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 55, in __init__
reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 32, in __init__
infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 237, in ffmpeg_parse_infos
proc = sp.Popen(cmd, **popen_params)
File "C:\Program Files (x86)\PsychoPy2\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Program Files (x86)\PsychoPy2\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] Le fichier spécifié est introuvable
It seems to be something wrong with the ffmpeg executable but I don't understand what.
Do you have any idea ?
Thank you very much fo advance !
Have a nice day.
Ivane

golang appengine - filename too long

I developed an appengine application in GO and now I tried to use the androidpublisher api. For this I need many dependencies like:
github.com/google/google-api-go-client
github.com/golang/oauth2
google.golang.org/appengine
google.golang.org/appengine/urlfetch
I tried to setup oauth2 authentication for google-api-go-client according to the example in https://github.com/golang/oauth2
Everything looks fine but I can't run the app-server anymore on my windows development machine. It complains about too long filenames:
INFO 2016-08-20 22:48:03,786 devappserver2.py:769] Skipping SDK update check.
INFO 2016-08-20 22:48:03,960 api_server.py:205] Starting API server at: http://localhost:64053
INFO 2016-08-20 22:48:03,969 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-08-20 22:48:03,974 admin_server.py:116] Starting admin server at:http://localhost:8000
Exception in thread Instance Adjustment: Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\work\go_appengine\google\appengine\tools\devappserver2\module.py",line 1485, in _loop_adjusting_instances
self._adjust_instances()
File "C:\work\go_appengine\google\appengine\tools\devappserver2\module.py",line 1460, in _adjust_instances
self._add_instance(permit_warmup=True)
File "C:\work\go_appengine\google\appengine\tools\devappserver2\module.py",line 1338, in _add_instance
expect_ready_request=perform_warmup)
File "C:\work\go_appengine\google\appengine\tools\devappserver2\go_runtime.py",line 174, in new_instance
if self._go_application.maybe_build(self._modified_since_last_build):
File "C:\work\go_appengine\google\appengine\tools\devappserver2\go_application.py",line 304, in maybe_build
self._extras_hash, old_extras_hash = (self._get_extras_hash(),
File "C:\work\go_appengine\google\appengine\tools\devappserver2\go_application.py",line 247, in _get_extras_hash gab_stdout,
_ = self._run_gab(gab_args, env={})
File "C:\work\go_appengine\google\appengine\tools\devappserver2\go_application.py",line 175, in _run_gab
gab_extra_args, env)
File "C:\work\go_appengine\google\appengine\tools\devappserver2\go_application.py",line 111, in _run_gab
env=env)
File "C:\work\go_appengine\google\appengine\tools\devappserver2\safe_subprocess.py",line 74, in start_process
stdin=subprocess.PIPE, startupinfo=startupinfo)
File "C:\Python27\lib\subprocess.py", line710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 206] The filename or extension is too long
I think my GOPATH is set up wrong so he gives all gofiles as argument to go-app-builder.exe.
My project is under C:\Users\me\project\ that's where the gopath points to and were I'm standing when I type:
goapp.bat serve .
Can someone help to fix this problem? Thank you.
EDIT
My project structure is like this:
How should i set my GOPATH?
GOPATH
$GOPATH
app.yaml
cron.yaml
pkg
src
testapp
app.go
golang.org
x
oauth2
Edit 2
I tried to move my GOPATH to project-root-dir/gopath but now i get this error message:
Exception in thread Instance Adjustment: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 810, in
__bootstrap_inner
self.run() File "C:\Python27\lib\threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs) File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\module.py", line 1486, in _loop_adjusting_instances
self._adjust_instances() File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\module.py", line 1461, in _adjust_instances
self._add_instance(permit_warmup=True) File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\module.py", line 1339, in _add_instance
expect_ready_request=perform_warmup) File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\go_runtime.py", line 176, in new_instance
if self._go_application.maybe_build(self._modified_since_last_build): File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\go_application.py", line 304, in maybe_build
self._extras_hash, old_extras_hash = (self._get_extras_hash(), File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\go_application.py", line 247, in _get_extras_hash
gab_stdout, _ = self._run_gab(gab_args, env={}) File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\go_application.py", line 175, in _run_gab
gab_extra_args, env) File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\go_application.py", line 111, in _run_gab
env=env) File "C:\Users\Indra\development\tools\go_appengine\google\appengine\tools\devappserver2\safe_subprocess.py", line 74, in start_process
stdin=subprocess.PIPE, startupinfo=startupinfo) File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite) File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo) WindowsError: [Error 87] Falscher Parameter
for all non german users it complains about a wrong parameter
I solved the problem by setting my GOPATH.
It's set now like this:
GOPATH=C:\Users\me\development\appengine\gopath;C:\Users\me\project
Now everything works find and the uploaded file is much smaller now. 2MB vs. 11MB.
Thanks for the tip.

Categories

Resources