elichai2
elichai2

Reputation: 1405

Using ADB from Python


I want to run adb commands from python and I've found google's own library for that but it doesn't work.
https://github.com/google/python-adb

This Is the Code I've used: (It's from the example)

import os.path as op

from adb import adb_commands
from adb import sign_m2crypto

signer = sign_m2crypto.M2CryptoSigner(
    op.expanduser('~/.android/adbkey'))

device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])

This is the error I get:

Traceback (most recent call last):
  File "/home/elichai2/PycharmProjects/Test/python_adb.py", line 9, in <module>
    device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 76, in ConnectDevice
    return cls.Connect(handle, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 99, in Connect
    device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 277, in Connect
    cmd, arg0, arg1, banner = cls.Read(usb, ['CNXN', 'AUTH'])
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 235, in Read
    actual_checksum = cls.CalculateChecksum(data)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 187, in CalculateChecksum
    return sum(map(ord, data)) & 0xFFFFFFFF
TypeError: ord() expected string of length 1, but int found

Any ideas?

Upvotes: 2

Views: 36201

Answers (3)

JGC
JGC

Reputation: 6373

A more recently maintained option might be https://github.com/JeffLIrion/adb_shell. The Google python-adb package website refers to this one as a better alternative.

Upvotes: 1

999masks
999masks

Reputation: 41

Have you tried to install these dependencies? from here [GIthub]: https://github.com/google/python-adb

Upvotes: 1

Diego Torres Milano
Diego Torres Milano

Reputation: 69318

You can try AndroidViewClient/culebra's adbclient.py which is an ADB client implemented in python.

This is a simple example of how to use AdbClient alone without AndroidViewClient.

Upvotes: 4

Related Questions