So I have been following these documentations so that I can print on my thermal printer through python.
I am running Ubuntu and have the pyusb module installed.
The printer is a Rongta RP58, and it's idVendor and idProduct were found through the lsusb command (0fe6:811e).
Just like in the instructions, I enter:
from escpos.printer import Usb
p = Usb(0x0fe6, 0x811e)
but the error appears
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/testerdell/.local/lib/python2.7/site-packages/escpos/printer.py", line 51, in __init__
self.open()
File "/home/testerdell/.local/lib/python2.7/site-packages/escpos/printer.py", line 62, in open
check_driver = self.device.is_kernel_driver_active(0)
File "/home/testerdell/.local/lib/python2.7/site-packages/usb/core.py", line 1061, in is_kernel_driver_active
self._ctx.managed_open()
File "/home/testerdell/.local/lib/python2.7/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/home/testerdell/.local/lib/python2.7/site-packages/usb/core.py", line 120, in managed_open
self.handle = self.backend.open_device(self.dev)
File "/home/testerdell/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 786, in open_device
return _DeviceHandle(dev)
File "/home/testerdell/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 643, in __init__
_check(_lib.libusb_open(self.devid, byref(self.handle)))
File "/home/testerdell/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
In the documentation it suggested to create a rule that grants access, but it hasn't worked for me.
sudo nano /etc/udev/rules.d/99-escpos.rules
is the command I use to edit the file, and this is what's inside
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fe6", ATTRS{idProduct}=="811e", MODE="0664", GROUP="dialout"
after changing anything in that file, I run this code:
sudo service udev restart
I am not sure how else I can give USB access to python.
When using direct root access with
sudo su root
the system says "ImportError: No module named escpos.printer". I wouldn't want to enter the password for root access every single time.
Is there a problem with my udev rules, groups, mode, user permissions?
Any help is greatly appreciated! Thanks in advance :)
Change the mode from 664 to 666 in your udev rule and it will work.
Related
I was trying Streamlit 1.13 on Windows 10, where I encountered the following error:
Z:\>streamlit run st1.py
2022-10-04 02:25:28.218 INFO numexpr.utils: NumExpr defaulting to 4 threads.
Welcome to Streamlit!
If you're one of our development partners or you're interested in getting
personal technical support or Streamlit updates, please enter your email
address below. Otherwise, you may leave the field blank.
http://localhost:8501
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\http1connection.py", line 276, in _read_message
delegate.finish()
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\routing.py", line 268, in finish
self.delegate.finish()
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\web.py", line 2322, in finish
self.execute()
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\web.py", line 2344, in execute
self.handler = self.handler_class(
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\web.py", line 239, in __init__
self.initialize(**kwargs) # type: ignore
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\web\server\routes.py", line 49, in initialize
self._pages = get_pages()
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\web\server\server.py", line 397, in <lambda>
for page_info in source_util.get_pages(
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\source_util.py", line 155, in get_pages
"script_path": str(main_script_path.resolve()),
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1215, in resolve
s = self._flavour.resolve(self, strict=strict)
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 215, in resolve
s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 1] Incorrect function: 'st1.py'
The installation of streamlit was complete: initially there was a conflict which I fixed, I also installed it in Anaconda and the error was the same.
I checked the exact streamlit file which rised the exception and changed the script to print the actual path of the script and it was correct, as well as the file was there.
#File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\source_util.py", line 155, in get_pages
def get_pages(main_script_path_str: str) -> Dict[str, Dict[str, str]]:
global _cached_pages
print("main_script_path_str=",main_script_path_str) #DEBUG
# Avoid taking the lock if the pages cache hasn't been invalidated.
pages = _cached_pages
if pages is not None:
return pages
The problem was with the location of the script on a RAM disk. Moving it to the a regular disk resolved it.
Another question with this Win error reminded me that the drivers of Windows RAM drives, at least the ones I've used such as Imdisk or OSFMount, seem to have missing support of some of the OS file functions.
OSError: [WinError 1] Incorrect function
E.g. "Rust" also had errors when trying to build source located in any of these RAM drives on Windows.
I am still quite new to USB protocol, and I need help extracting data from a digital multimeter using a USB connection and Python on my Raspberry Pi. Here I have a very basic Python script for reading from a generic USB device, and note that the idVendor and idProduct variables are correct for the multimeter I am using:
import usb.core
dev=usb.core.find(idVendor=0x067b,idProduct=0x2303)
ep=dev[0].interfaces()[0].endpoints()[0]
i=dev[0].interfaces()[0].bInterfaceNumber
dev.reset()
if dev.is_kernal_driver_active(i):
dev.detach_kernal_driver(i)
dev.set_configuration()
eaddr=ep.bEndpointAddress
r=dev.read(eaddr,1024)
print(len(r))
When I try to execute the script while the multimeter is reading a voltage, I receive the following error message:
Traceback (most recent call last):
File "usbRead.py", line 6, in <module>
dev.reset()
File "/home/pi/.local/lib/python2.7/site-packages/usb/core.py", line 949, in reset
self._ctx.managed_open()
File "/home/pi/.local/lib/python2.7/site-packages/usb/core.py", line 113, in wrapper
return f(self, *args, **kwargs)
File "/home/pi/.local/lib/python2.7/site-packages/usb/core.py", line 131, in managed_open
self.handle = self.backend.open_device(self.dev)
File "/home/pi/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 804, in open_device
return _DeviceHandle(dev)
File "/home/pi/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 652, in __init__
_check(_lib.libusb_open(self.devid, byref(self.handle)))
File "/home/pi/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 604, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
------------------
(program exited with code: 1)
Press return to continue
My apologies if this is an amateur question, but I've been trying my best to solve the insufficient permissions problem, but every solution I could find is filled with jargon that I'm hopeless in understanding. There was one thread that discussed changing things in a "rule file", and when I tried that, I ended up completely bricking the Raspberry Pi I was using!
Please help a novice like me on how I can be able to get data from this USB multimeter. Thank you so much in advance! I can answer questions for additional information as best I can.
I tried running code as root, this is not helped.
I need raw access to usb device, not HID!
Traceback (most recent call last):
File "hiqos.py", line 20, in <module>
alternate_setting = usb.control.get_interface(device,interface_number)
File "/usr/local/lib/python2.7/site-packages/usb/control.py", line 244, in get_interface
data_or_wLength = 1)[0]
File "/usr/local/lib/python2.7/site-packages/usb/core.py", line 1034, in ctrl_transfer
self._ctx.managed_claim_interface(self, interface_number)
File "/usr/local/lib/python2.7/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/usb/core.py", line 167, in managed_claim_interface
self.backend.claim_interface(self.handle, i)
File "/usr/local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 811, in claim_interface
_check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
File "/usr/local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
I had the same error. I've also tried
sudo kextload -bundle-id com.apple.driver.AppleUSBFTDI
but my MacBook can't find it, although it was supposed to work for High Sierra. The only real thing I've been able to do is read input from /dev/disk3 after unmounting it by:
sudo diskutil unmountdisk /dev/disk3
and then
sudo cat /dev/disk3 | hexdump
I am trying to interface with an Ocean optics spectrometer using seabreeze (seabreeze) and pyseabreeze (pyseabreeze).
If I enter python from the command prompt (cmd) in windows and enter the following code line by line, it works. However, if I put it in a script (spec_test.py) and try running it from cmd.exe by using 'python spec_test.py', it will not work.
I have searched around a lot for similar problems but none seem to cover the issue I'm having. I am running Windows 7 64 bit, python 3.5.2 installed using anaconda. I also had to install pyusb and libusb to use pyseabreeze.
The code:
import seabreeze
seabreeze.use('pyseabreeze')
import seabreeze.spectrometers as sb
devs = sb.list_devices()
print(devs)
spec = sb.Spectrometer(devs[0])
print(spec.model)
and the error message I get:
[<SeaBreezeDevice USB2000PLUS:FLMS02379>]
Traceback (most recent call last):
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\common.py", line 14, in decorated_func
return func(*args, **kwargs)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\spectrometer.py", line 46, in open
self.open_device(device.handle)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\communication.py", line 37, in open_device
device.set_configuration()
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\core.py", line 869, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\core.py", line 148, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\backend\libusb0.py", line 493, in set_configuration
_check(_lib.usb_set_configuration(dev_handle, config_value))
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\backend\libusb0.py", line 431, in _check
raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'libusb0-dll:err [set_configuration] could not set config 1: win error: The parameter is incorrect.\r\n'
Traceback (most recent call last):
File "<ipython-input-9-ead886eb3666>", line 1, in <module>
runfile('C:/Users/Raman Lab/Python code/Spectrometers/spec_testing.py', wdir='C:/Users/Raman Lab/Python code/Spectrometers')
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Raman Lab/Python code/Spectrometers/spec_testing.py", line 7, in <module>
spec = sb.Spectrometer(devs[0])
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\spectrometers.py", line 62, in __init__
self._open_device(device)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\spectrometers.py", line 90, in _open_device
lib.device_open(self._dev)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\wrapper.py", line 81, in device_open
return device.interface.open(device)
File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\common.py", line 23, in decorated_func
raise SeaBreezeError(msg)
SeaBreezeError: An error occured during opening.
Thanks for any help!
Edit:
For some reason I figured this out, thought it might help describe the issue. If I enter interactive python from cmd.exe and paste the code instead of typing it in manually, I get the same error. This makes me think (most likely I'm wrong) that it is somehow tied up with speed of imports. I tried adding a sleep for a few seconds in between lines 3 and 5, to simulate what happens when I am typing in the prompt, but that didn't help. I hope this was descriptive enough.
Your initial guess was not far off. I had exactly the same problem, however, on Windows 7 32bit with Python 2.7. The example code gchaks linked to was running fine.
When I tried executing the script several times in quick succession, the error message changed and pointed at a empty devices list. I added a delay of 2 seconds after
devs = sb.list_devices()
and that solved the problem. Your code was running just fine on a Linux machine btw.
Another hint: If your code should run once, but then you run into another error message, make sure you close the device connection or dis- and reconnect the spectrometer.
When starting /etc/init.d/celeryd I get the following error below. I made sure all the directories are read and writable with the user that I am starting it as. I even did touch file to make sure in all the places that there is a directive for a file to write to.
(community)community#community:~$ /etc/init.d/celeryd start
bot_server.settings.production
celery multi v3.1.11 (Cipater)
> Starting nodes...
> w1.bot_server#community.net: Traceback (most recent call last):
File "/home/community/community-forums/bot_server/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/djcelery/management/commands/celeryd_detach.py", line 26, in run_from_argv
detached().execute_from_commandline(argv)
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/celery/bin/celeryd_detach.py", line 160, in execute_from_commandline
**vars(options)
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/celery/bin/celeryd_detach.py", line 42, in detach
with detached(logfile, pidfile, uid, gid, umask, working_directory, fake):
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/celery/platforms.py", line 383, in detached
maybe_drop_privileges(uid=uid, gid=gid)
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/celery/platforms.py", line 520, in maybe_drop_privileges
initgroups(uid, gid)
File "/home/community/.virtualenvs/community/local/lib/python2.7/site-packages/celery/platforms.py", line 473, in initgroups
return os.initgroups(username, gid)
OSError: [Errno 1] Operation not permitted
* Child terminated with errorcode 1
FAILED
I am using:
Django==1.6.3
celery==3.1.11
celerymon==1.0.3
django-celery==3.1.10
django-celery-with-redis==3.0
OSError errno 1 looks like a permissions issue:
OSError: [Error 1] Operation not permitted
Looks like the issue is on os.initgroups, which calls initgroups on the system -- see man initgroups
From your prompt it looks like you're using some sort of role account, I'd guess there is some issue with how your role/group permissions are set up with respect to the files django is accessing.
Edit:
From man initgroups:
DESCRIPTION
The initgroups() function initializes the group access list by reading
the group database /etc/group and using all groups of which user is a member.
The additional group group is also added to the list.
Can community read /etc/group?