Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors on Windows #97

Open
demonguy opened this issue Apr 9, 2024 · 2 comments
Open

Errors on Windows #97

demonguy opened this issue Apr 9, 2024 · 2 comments

Comments

@demonguy
Copy link

demonguy commented Apr 9, 2024

I tried to use this library to access android devices via python script. So far I can:

  1. my script works on Ubuntu and Mac
  2. on Windows, my driver and device works fine with native Android adb tool
  3. zadig shows my device driver is WinUSB
  4. And I got errors below

Did I miss anything?

Looking for adb devices ...
Traceback (most recent call last):
  File "C:\Users\cy_ss_000.CY\miTrace\miTrace.py", line 146, in <module>
    devs = init_devices()
  File "C:\Users\cy_ss_000.CY\miTrace\miTrace.py", line 46, in init_devices
    dev.connect()
  File "C:\Users\cy_ss_000.CY\miTrace\lib/adb_shell\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\cy_ss_000.CY\miTrace\lib/adb_shell\adb_shell\adb_device.py", line 221, in connect
    self._transport.connect(adb_info.transport_timeout_s)
  File "C:\Users\cy_ss_000.CY\miTrace\lib/adb_shell\adb_shell\transport\usb_transport.py", line 238, in connect
    transport = self._device.open()
  File "C:\Users\cy_ss_000.CY\AppData\Local\Programs\Python\Python39\lib\site-packages\usb1\__init__.py", line 2055, in open
    mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
  File "C:\Users\cy_ss_000.CY\AppData\Local\Programs\Python\Python39\lib\site-packages\usb1\__init__.py", line 127, in mayRaiseUSBError
    __raiseUSBError(value)
  File "C:\Users\cy_ss_000.CY\AppData\Local\Programs\Python\Python39\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]

image

@vpelletier
Copy link
Owner

As this is an error reported by libusb_open (so the C library directly), the first level of explanation I can give comes from the libusb1 documentation for libusb_open.

Then, the question becomes: Why does your windows user somehow not have the permission to open that device ?

My first thought was libusb_detach_kernel_driver (exposed as DeviceHandle.detachKernelDriver in this module), especially as you mention ADB may be installed on that system (and could hence somehow maybe take precedence over WinUSB ? I'm not sure), but the libusb1 documentation states it is not available on windows.

Searching a bit, I find libusb/libusb#1300 which suggests to me the 32bits library (and hence main executable ?) may somehow not be allowed to open devices running on a 64bits machine. What bit-width the python interpreter you are using is compiled for ?

@vpelletier
Copy link
Owner

vpelletier commented Apr 16, 2024

Another approach to this question: here are two projects which implement the adb command in python, and both happen to use my module to access the USB bus:

https://github.com/google/python-adb (archived)

https://github.com/JeffLIrion/adb_shell (active)

EDIT: ...and I forgot to finish my thought: I'm not suggesting you use these projects' code (though you may decide to), just that they could maybe have bug reports or code which could point you in the direction of how to resolve the present issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants