Comments (6)
Change except exceptions.UsbDeviceNotFoundError:
to except adb_shell.exceptions.UsbDeviceNotFoundError:
from adb_shell.
Already tried that, as I detailed above.
from adb_shell.
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.
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.
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.
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)
- Using pull on BytesIO object HOT 3
- Pushing large files always timeouts HOT 12
- Implement the pair command for Android 11+ devices HOT 6
- How to connect more than two devices at the same time? HOT 3
- AdbDeviceUsb not working with MacOS X due to error 'LIBUSB_ERROR_ACCESS [-3]' HOT 2
- default_transport_timeout_s is ignored HOT 1
- Add support for pulling directories HOT 2
- usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3] HOT 2
- adb server claims usb device: results in USBErrorBusy
- Feature request install package analog to adb install HOT 4
- get return code of shell command HOT 4
- How can I get access to the device with password to adb? HOT 5
- Add adb forward functionality
- packaging this project for Debian HOT 3
- Improvement
- Streaming Shell doesn't result in a stream ?
- usb1.USBErrorBusy: LIBUSB_ERROR_BUSY [-6] when connect to device HOT 2
- Timeout shell commands after gaining root on device
- Please avoid re-tagging
- No ability to list attached devices?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adb_shell.