PyUsb: "insufficient permissions". macOS Big Sur - python

I'm following this tutorial for pyusb but when I get this far into the code, I get the error: raise USBError(_strerror(ret), ret, _libusb_errno[ret]) usb.core.USBError: [Errno 13] Access denied (insufficient permissions). Here is the code I wrote:
import usb.core
import usb.util
VID = 0x046d
PID = 0xc07e
dev = usb.core.find(idVendor=VID, idProduct=PID)
ep = dev[0].interfaces()[0].endpoints()[0]
i = dev[0].interfaces()[0].bInterfaceNumber
dev.reset()
if dev.is_kernel_driver_active(i):
dev.detach_kernel_driver(i)
r = dev.read(eaddr, 1024)
print(len(r))
As I said in the title, I'm on macOS Big Sur Version 11.4 and I'm trying to read from Bus 020 Device 029: ID 046d:c07e Logitech Inc. Gaming Mouse G402.
Thanks.

The error says "Access denied (insufficient permissions)". You have to run your code with sudo. Like: "sudo python3 <yourscript.py>".

Related

other error while trying to print the receipt using escposprinter python library in windows10

I am developing hotel billing system that prints the bill receipt using thermal printer but i am stuck at
[Errno None] Other errors
python3.9
library: escposprinter &
libusb-1.0,
plateform:windows 10
Thermal printer: xlab xp-58III
from escposprinter import *
try:
Epson = printer.Usb(0x0416, 0x5011)
Epson.text('Hello World')
Epson.cut()
except Exception as e:
print("PRINTER ERROR: ", e)
Result: [Errno None] Other errors
if i remove try block then, Result: Process finished with exit code -1073740791 (0xC0000409)

Can't access file on remote server with os.startfile

I am trying to access a test text file on a server with the command os.startfile but I can't seem to make it work. I know it only fails because the text file is on the server and not on the computer but I have no idea how to access it.
Here's my code :
from os import startfile
path = "//10.2.30.61/c$/Qlikview_Tropal/Raport/test1.txt"
startfile("//10.00.00.00/c$/test/test1/test1.txt")
And I get this error : FileNotFoundError: [WinError 2]. I am on windows by the way.
Update_1 : I tried the enter os.startfile(os.path.normpath()) and i get this error : "filenotfounderror winerror 53 the network path was not found"
Thank you !!
You can do
from os import start file
#put two \\ to get one \
path = "\\\\10.2.30.61\\c$\\Qlikview_Tropal\\Raport\\test1.txt"
startfile(r"\\10.00.00.00\c$\test\test1\test1.txt")
https://stackoverflow.com/a/43205543/14579156

Python : PyUSB can't access usb device

I am trying to read an usb bar code reader from my python script, via the https://github.com/pyusb/pyusb library.
import usb.core
import usb.util
VENDOR_ID = 8208
PRODUCT_ID = 30264
dev = usb.core.find(idVendor=VENDOR_ID,
idProduct=PRODUCT_ID)
dev.set_configuration()
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
data = ep.read(ep.wMaxPacketSize, 8000000)
Unfortunately, this leads to a "USBError: [Errno 13] Access denied (insufficient permissions)" issue.
I tried to run the script as a sudo, but it didn't help. The script work fine on my Ubuntu laptop, but I am now trying to move it to Mac OS. One of the differences is that I do have a "detach_kernel" before hand on Linux, but this function make a fail with "not implemented on this OS" error with Mac Os...

Error occuring while connecting USB camera and two arduino with raspberry pi simultaneously

I have the following code for connecting one usb camera and two arduino board with raspberry pi.
import cv2.cv as cv, time
import numpy as np
import serial,time
ser1 = serial.Serial('/dev/ttyUSB0')
ser2 = serial.Serial('/dev/ttyUSB1')
capture = cv.CaptureFromCAM(0)
while True:
try:
for i in range(10):
x = ser1.readline()
with open("test1.txt", "a") as myfile:
myfile.write(x)
img = cv.QueryFrame(capture)
print("Taking image...")
cv.SaveImage('pic{:>05}.jpg'.format(i), img)
time.sleep(2)
y = ser2.readline()
with open("test2.txt", "a") as myfile:
myfile.write(y)
cv.WaitKey(1)
except:
continue
The camera is for taking continuous image frame and storing the latest 10 images in the current folder in each 2sec(Overwriting previous data). The datas from the arduino also logging into two separate text file. While running the code i am getting error messages as shown below.
pi#raspberrypi ~ $ sudo python accident.py
libv4l2: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Device or resource busy
libv4l1: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT
Taking image...
Taking image...
Taking image...
^Z
[4]+ Stopped
While I searched for this problem , I found that, all the USB port of rasp-pi having the same serial port.
Can anybody help me to solve this issue...

No module named usb.core

How can I remove this error in the below mentioned program? The error iI'm getting is
ImportError: No module named usb.core
and my code is:
import usb.core
import usb.util
# find our device
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)
# was it found?
if dev is None:
raise ValueError('Device not found')
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
# write the data
ep.write('test')
OS is windows 8 64-bit [...]
ValueError: No backend available
Allow me to translate: You forgot to install the correct USB driver.
USB devices need a driver to work in Windows. Look at PyUSB website for details, and use Zadig to generate and install the driver (e.g. LibUSB-Win32) for you. This program takes care of the certificate that Windows 8 wants to see for your drivers inf file.
Btw: The VID you should use for USB development is 0x4242.
For error:
C:\Users\RAHUL\Desktop\python progrms\USBsample.py, line 5, in <module>
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001) File "C:\Python27\lib\site-
packages\usb\core.py", line 864, in find raise ValueError('No backend available')
ValueError: No backend available
Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.
python -m pip install pyusb libusb
Fixed this for me.

Categories