Get more info out of a Python3 OSError - python

I am using Python3 on Ubuntu with the HID module python3-hid.
If I use it to open a device, I simply get back:
OSError: open failed
Which prompted me to handle the exception, and see if I can get more information out of it:
try:
h.open(vend, prod)
except OSError as error :
print(error)
print(error.strerror)
print(error.filename)
sys.exit(1)
To my surprise, no further information was available, as both strerror and filename were None.
open failed
None
None
NOTE: My open() succeeds when I run as root, so I know this is a permission thing. But why can't this OSError tell me that it is permission related?
How do I get all the details (specific reason of failure, and filename involved) out of an OSError?
UPDATE: The traceback leads to hid.pyx file:
Traceback (most recent call last):
File "/tmp/./tst.py", line 30, in <module>
h.open(vend, prod)
File "hid.pyx", line 66, in hid.device.open
I am not sure why my system can't find the hid.pyx file.
$ dpkg -S hid.pyx
dpkg-query: no path found matching pattern *hid.pyx*
Checking the upstream package from Ubuntu... it turns out that python3-hid is part of the software for a crypto coin wallet? Strange. I think I will skip using this module, and maybe write directly in C, using libhidapi-hidraw which this python module also uses.

Related

docker-compose: ValueError: bad marshal data (unknown type code)

My setup was working fine but for some reason docker-compose --help now yields:
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 7, in <module>
from compose.cli.main import main
File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 14, in <module>
from inspect import getdoc
ValueError: bad marshal data (unknown type code)
find /usr -name '*.pyc' -delete fixed the problem.
If you get that error, the compiled version of the Python module (the .pyc file) is corrupt probably. Gentoo Linux provides python-updater, but in Debian the easier way to fix: just delete the .pyc file. If you don't know the pyc, just delete all of them (as root):
(reference: https://www.py4u.net/discuss/17141)

OSError: operation not permitted os.setegid

I get an "operation not permitted" traceback with trying to use os.setegid(). I've found a few answers to similar questions to this one, but the questions are more complicated than my case, and the answers presume the users did a setuid first, or suggest setting the setgid bit on the directory.
This issue is much simpler. I'm just doing a os.setegid with group id that I am a member of. In the shell I can use sg(), newgrp(), or chgrp() with the same group successfully. Why does this python command fail?
>>> import os
>>> os.setegid(34007)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 1] Operation not permitted
>>>
I am using RHEL7 and an older version of python (2.7.5) but the same error occurs with python 3.6.10, though in that case it's a PermissionError rather than an OSError.
Ensure you're running as root.
https://www.geeksforgeeks.org/python-os-getegid-and-os-setegid-method/
...method is typically available only to the superuser. Superuser
means a root user or an administrative user who has all the
permissions to run or execute any program in the operating system

Accessing Sub Directories and Files Within System32 Using Python 3

I have the following code:
import os
print (os.listdir("C:/Windows/System32/config"))
print (os.listdir("C:/Windows/System32/winevt"))
I am running this Python script as an administrator and confirmed those directories in fact exist.
The first line outputs with some files and folders, but not all files. For example, there is a registry hive contained within called "SOFTWARE" which does not appear in the output.
The second line says the path wasn't identified. Here is the full output:
['Journal', 'RegBack', 'systemprofile', 'TxR']
Traceback (most recent call last):
File "test.py", line 3, in <module>
print (os.listdir("C:/Windows/System32/winevt"))
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:/Windows/System32/winevt'
This module (os.listdir), works pretty much everywhere else on the system, but not within System32. I suspect this may be permission related, but am not too sure on how to fix it as I am already running the script as an administrator.
Help would be appreciated. Thanks!

python cannot find GL

Trying to use pyglet1.2alpha1 under FreeBSD with python3.3 on an amd64 machine, I get
$ python ~/.local/lib/python3.3/site-packages/pyglet/gl/gl_info.py
Traceback (most recent call last):
File "~/.local/lib/python3.3/site-packages/pyglet/lib.py", line 111, in load_library
lib = ctypes.cdll.LoadLibrary(name)
File "/usr/local/lib/python3.3/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/local/lib/python3.3/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: Shared object "GL" not found, required by "python"
During handling of the above exception, another exception occurred:
[…]
File "~/.local/lib/python3.3/site-packages/pyglet/lib.py", line 118, in load_library
if ((self.linux_not_found_error not in o.message) and
AttributeError: 'OSError' object has no attribute 'message'
I have tested my Mesa installation by running glxgears (works), I have tried installing PyOpenGL for comparison (which does not work, because it depends on the PIL, which is not fit for python3.3), and just to make sure I have reinstalled python3.3 after installing the mesa-demos and freeglut, and still no change.
In python2.7, I get the same error
OSError: Shared object "GL" not found, required by "python2"
(without the problem of During handling of the above exception, another exception occurred), also after installing PyOpenGL (which works as expected).
What is the problem here? How do get pyglet to work?
The various python files that come with pyglet and try to load external resources test explicitly if they run on linux. Consequently, they don't evaluate to the right things on FreeBSD. When replacing sys.platform.startswith('linux') with sys.platform.startswith('linux') or sys.platform.startswith('freebsd') in the files listed below, it seems to work.
pyglet/lib.py
pyglet/app/base.py
pyglet/gl/__init__.py
pyglet/image/codecs/__init__.py
pyglet/input/__init__.py
pyglet/media/drivers/openal/__init__.py

Why do i get this traceback error?

This is the error i get:
Traceback (most recent call last):
File "dwload.py", line 9, in <module>
File "Pmw\__init__.pyc", line 28, in <module>
WindowsError: [Error 3] The system cannot find the path specified: "C:\\Users\\P
'sao\\Desktop\\dist\\library.zip\\Pmw/*.*"
I get the error after compiling the python file into the executable with py2exe.
Does anybody know why i get this error?
Found the solution: http://billyjin.kodingen.com/punbb-1.3.4/viewtopic.php?id=310
Well, the error message says that the path was not found, and if you look at the path, you appear to have mixed up backslashes and slashes as path separators. How are you constructing the path you're using?
I had the same problem when using pyinstaller and tkinter table (py 2.7). The problem was solved by removing the Pwm dependency in the tkintertable lib metadata. Its will help you, if pwm dont used in program
Finally, I found the solution:
First, you need to run the bundlepmw.py in the C:\Python27\Lib\site-packages\Pmw\build\lib\Pmw\Pmw_1_3\bin folder following this command: python bundlepmw.py C:\Python27\Lib\site-packages\Pmw\Pmw_1_3\lib to create the Pmw.py.
Read this page: folk.uio.no/hpl/scripting/doc/python/Pmw/dynamicloader.html, after fixing the bundlepmw.py based on this link sourceforge.net/p/pmw/discussion/33675/thread/f0bd7f34.
You should be able to generate the Pmw.py file.
Then copy the Pmw.py plus PmwBlt.py and PmwColor.py into the main script directory and run your setup.py. Sweet

Categories