Giter Site home page Giter Site logo

Comments (6)

JeffLIrion avatar JeffLIrion commented on July 21, 2024

Change except exceptions.UsbDeviceNotFoundError: to except adb_shell.exceptions.UsbDeviceNotFoundError:

from adb_shell.

threadreaper avatar threadreaper commented on July 21, 2024

Already tried that, as I detailed above.

from adb_shell.

JeffLIrion avatar JeffLIrion commented on July 21, 2024

The name exceptions is not defined. It's the same as if you did this:

try:
    1/0
except exceptions.Something:
    print("Caught!")

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-1-12d64cb3b5d5> in <module>()
      1 try:
----> 2     1/0
      3 except exceptions.Something:

ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

NameError                                 Traceback (most recent call last)
<ipython-input-1-12d64cb3b5d5> in <module>()
      1 try:
      2     1/0
----> 3 except exceptions.Something:
      4     print("Caught!")
      5 

NameError: name 'exceptions' is not defined

from adb_shell.

threadreaper avatar threadreaper commented on July 21, 2024

That was my inclination as well, but again, I have already tried that. But the error I'm getting is not related to exceptions not being defined. Here's the complete error message:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 597, in _find_first
    return next(cls._find_devices(setting_matcher, device_matcher=device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s))
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/michael/projects/HUprojects/scatter/shell.py", line 22, in <module>
    device = AdbDeviceUsb()
  File "/usr/lib/python3.8/site-packages/adb_shell/adb_device.py", line 1200, in __init__
    transport = UsbTransport.find_adb(serial, port_path, default_transport_timeout_s)
  File "/usr/lib/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 620, in find_adb
    return cls._find(
  File "/usr/lib/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 507, in _find
    return cls._find_first(setting_matcher, device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s)
  File "/usr/lib/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 599, in _find_first
    raise exceptions.UsbDeviceNotFoundError('No device available, or it is in the wrong configuration.')
adb_shell.exceptions.UsbDeviceNotFoundError: No device available, or it is in the wrong configuration.

As you can see, no reference to exceptions not being defined.

This is my try/except block currently:

try:
    device.connect(rsa_keys=[signer], auth_timeout_s=0.1)
except adb_shell.exceptions.UsbDeviceNotFoundError:
    print('Error: Device.not found')
    sys.exit(1)
except usb1.USBErrorBusy:
    os.system('adb kill-server')
    device.connect(rsa_keys=[signer], auth_timeout_s=0.1)
finally:
    if device.available:
        print("Device successfully connected.")

from adb_shell.

JeffLIrion avatar JeffLIrion commented on July 21, 2024

The traceback is what I needed to see. You didn't get a "name is not defined" error because the code never got that far.

  File "/home/michael/projects/HUprojects/scatter/shell.py", line 22, in <module>
    device = AdbDeviceUsb()

This is where your exception occurred. It's looking for the USB device, but it doesn't find it.

Unfortunately, I don't know the solution. Catching the exception won't help because if it can't find the USB device then nothing after that will work. Maybe if you kill the ADB server first it would work?

This is why USB support is marked as experimental. If you figure out how the solution, please share it!

from adb_shell.

threadreaper avatar threadreaper commented on July 21, 2024

Oh geez, now I feel dumb. I don't know how I managed to overlook this. All I needed to do was add:

try:
    device = AdbDeviceUsb()
except adb_shell.exceptions.UsbDeviceNotFoundError:
    print('Error: Device not found')
    sys.exit(1)

This handles the error condition I was looking for. I was so sure it was coming from the device.connect() attempt I wasn't reading the traceback as closely as I should have. Thank you for your assistance.

from adb_shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.