pure-python-adb icon indicating copy to clipboard operation
pure-python-adb copied to clipboard

AttributeError: 'NoneType' object has no attribute 'shell'

Open iverdr17 opened this issue 5 years ago • 6 comments

Traceback (most recent call last): File "Serial.py", line 5, in device.shell("echo hello world !") AttributeError: 'NoneType' object has no attribute 'shell'

I am getting this error when trying to run this code on linux from ppadb.client import Client as AdbClient

Default is "127.0.0.1" and 5037

client = AdbClient(host="127.0.0.1", port=5037) device = client.device("emulator-5554") device.shell("echo hello world !") inside Serial.py

Am I missing anything?

iverdr17 avatar May 14 '20 18:05 iverdr17

Hi @iverdr17 You can use adb -H 127.0.0.1 -P 5037 devices to check the device emulator-5554 is existing or not. When the device emulator-5554 is not existing, client.device("emulator-5554") will return None

Swind avatar May 14 '20 19:05 Swind

Hi @Swind List of devices attached DHE4C18C10003341 device This is what I am getting for adb -H 127.0.0.1 -P 5037 devices. That means I am connected with the device. The attribute error still exists when device.shell("echo hello world !") this is run. Not only that when I am trying to run the following code for reading logcat

from ppadb.client import Client def dump_logcat_by_line(connect): file_obj = connect.socket.makefile() for index in range(0, 10): print("Line {}: {}".format(index, file_obj.readline().strip()))

file_obj.close() connect.close()

client = Client() device = client.device("emulator-5554") device.shell("logcat", handler=dump_logcat_by_line)

The attribute error comes for file_obj, connect and shell.

iverdr17 avatar May 15 '20 08:05 iverdr17

Hi @iverdr17

List of devices attached
DHE4C18C10003341 device

The device emulator-5554 is not existing in the device list. If you want to connect to your device DHE4C18C10003341 You should use

client = Client()
device = client.device("DHE4C18C10003341")

Swind avatar May 15 '20 08:05 Swind

Hi @Swind Its working now. Is there any way to sort the data by TAG and then print. Thank you.

iverdr17 avatar May 15 '20 09:05 iverdr17

import ppadb

from ppadb.client import Client as AdbClient

adb = AdbClient(host='127.0.0.1', port=5037) print(adb.version()) print("getting list of devices") print(adb.devices()) print("connecting to Memu") device = adb.device("127.0.0.1:21503") print("connected") device.shell("echo hello world !")

error: AttributeError: 'Client' object has no attribute 'shell'

boludoz avatar Mar 31 '22 00:03 boludoz

are you trying to connect to an emulator?

Normally the adb.device("") would contain the serialnumber or the ip address with port 5555.

the print("connected") is not valid. You should always check that device is not None

ebisek-logi avatar Mar 31 '22 01:03 ebisek-logi