adb_shell
adb_shell copied to clipboard
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]
My operating system is windows and my python version is 3.11
with open(adbkey) as f:
priv = f.read()
with open(adbkey + '.pub') as f:
pub = f.read()
signer = PythonRSASigner(pub, priv)
device1 = AdbDeviceUsb(serial='1234567')
device1.connect(rsa_keys=[signer])
I tried to connect to a device via USB by my python code but failed.
Traceback (most recent call last):
File "C:\Users\xzp9097\Desktop\adb_operate\adb_test.py", line 58, in <module>
ao.connect()
File "C:\Users\xzp9097\Desktop\adb_operate\adb_test.py", line 21, in connect
self.device.connect()
File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\adb_shell\adb_device.py", line 675, in connect
self._available, self._maxdata = self._io_manager.connect(self._banner, rsa_keys, auth_timeout_s, auth_callback, adb_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\adb_shell\adb_device.py", line 221, in connect
self._transport.connect(adb_info.transport_timeout_s)
File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\adb_shell\transport\usb_transport.py", line 238, in connect
transport = self._device.open()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\usb1\__init__.py", line 2055, in open
mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\usb1\__init__.py", line 127, in mayRaiseUSBError
__raiseUSBError(value)
File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\usb1\__init__.py", line 119, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]
Then I reboot the system and try running the code again. It connected successed. I found out that if I use CMD to connect the device first, and then execute my code it would raise the error, unless reboot the system. How can I modify my code to solve this problem? Thanks a lot