-
Notifications
You must be signed in to change notification settings - Fork 61
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
adb_shell.exceptions.InvalidCommandError in connect()
with Android emulator
#81
Comments
def from_int(n):
return ''.join(chr((n >> (i * 8)) % 256) for i in range(4)).encode('utf-8') That is the opposite of adb_shell/tests/test_adb_device.py Lines 25 to 26 in 825294d
I don't know what Your exception is occurring here: adb_shell/adb_shell/adb_device.py Line 847 in 825294d
If you want more info, you need to turn on debug logging. |
Ok, but how do I make it work?) |
More info is needed to see what's going on. import logging
logging.getLogger().setLevel(logging.DEBUG) Post a log and I'll take a look. |
|
Try this with debug logging enabled and post a log. adb_controller = Controller("localhost", 5556)
try:
adb_controller.connect_to_device(timeout=10)
except:
pass
print(adb_controller.device._handle.bulk_read(1000, 5)) |
This is output:
Log:
|
That output is not from the same code I posted. |
Ok, i commented
|
OK, I see now. It looks like it's saying that it will only work if you use the key This is the reply you get when you try to connect:
Have you connected to the emulator using the official ADB binary? |
Yes, the official adb connect to emulator successfully |
Do you have a file If so, try using that in your |
Have you had a chance to try using the key |
Hello, Jeff, sorry for the silence, there was no access to the computer |
If i connect to Android console manually and enter |
Yes, please try that. |
Yes, I tried to make a signature with this key, but nothing |
Can you post the output from this, as you did before.
|
|
I need debug logs to see the data that's being sent and read. import logging
import os
from adb_shell import adb_device
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
logging.getLogger().setLevel(logging.DEBUG)
class Controller:
def __init__(self, host: str, port: int):
self.host, self.port = host, port
self.device, self._signer = None, None
def connect_to_device(self, timeout: int):
self.device = adb_device.AdbDeviceTcp(self.host, self.port, default_timeout_s=timeout)
self._make_sign("/root/.emulator_console_auth_token")
self.device.connect(auth_timeout_s=0.1, rsa_keys=[self._signer])
def _make_sign(self, path: str):
with open(os.path.expanduser(path)) as file:
rsa_key = file.read()
self._signer = PythonRSASigner("", rsa_key)
def shell(self, command: str) -> str:
output = self.device.shell(command, decode=True)
return output
if __name__ == '__main__':
adb_controller = Controller("localhost", 5556)
try:
adb_controller.connect_to_device(timeout=10)
except:
pass
print(adb_controller.device._handle.bulk_read(1000, 5)) |
I met the same problem after i ctrl+c a running "shell command".
I also noticed the timeout seems notworking. Following command stuck all the time: |
I can reproduce the "adb_shell.exceptions.InvalidCommandError" problem like following: Run:
|
connect()
with Android emulator
@kunzhipeng your issue is different. I changed the title of this issue to reflect that it is about an error when trying to connect to an Android emulator. I think the Ctrl+C issue you're describing here is even different than the new issue you created. I think the problem is that you're stopping the current task on the host computer -- i.e., running that she'll command via
Either way, when you try to run a new shell command, it expects a response to the new command but receives a response from the old command, hence the error. I'm not sure how to handle that other than closing the connection and reconnecting. |
Glad that I'm facing the exactly same issue here. I'm using Mac OS X Cata...blah, and using good old |
I replaced this line
|
So @JeffLIrion is the above log message enough for you to debug? |
@combacsa try using the key |
@JeffLIrion I tried with it but it failed with error, like it's not a permitable file for a RSA... exact log message is: |
|
(I'm kinda in a hurry, since I'm creating a code for a birthday present now...) |
Interestingly, when I just use Command: Output:
Then I just type the contents from '/Users/khbyun/.emulator_console_auth_token' like
then
So, there could be a sudden change happend in adb's socket protocol? |
Try making a backup of the key and then pasting that as the first line in the original.
|
+1 Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from adb_shell.adb_device import AdbDeviceTcp, AdbDeviceUsb
>>> from adb_shell.auth.sign_pythonrsa import PythonRSASigner
>>> import os.path as op
>>> with open(op.expanduser('~/.android/adbkey')) as f:
... priv = f.read()
...
>>> signer = PythonRSASigner('', priv)
>>> device2 = AdbDeviceTcp('localhost', 5554)
>>> device2.connect(rsa_keys=[signer])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/adb_shell/adb_device.py", line 219, in connect
cmd, arg0, arg1, banner = self._read([constants.AUTH, constants.CNXN], adb_info)
File "/usr/local/lib/python3.8/dist-packages/adb_shell/adb_device.py", line 758, in _read
raise exceptions.InvalidCommandError('Unknown command: %x' % cmd, cmd, (arg0, arg1))
adb_shell.exceptions.InvalidCommandError: ('Unknown command: 72646e41', 1919184449, (543451503, 1936617283))
>>> |
I just published a new release. It doesn't fix the problem, but the exception message will contain more information. Although I'm sure it will just be the same info in this post: #81 (comment) (Actually, it will only be the first part of it: "Android Console: Authent") This isn't a use case that I plan to support, but if someone wants to contribute a fix they are welcome to do so. |
Hi Jeff! I'm getting this error too. In my case emulator_console_auth_token is tiny "4ekw5I+6eOro0wvG" - |
If I empty the auth token file I get: DEBUG:adb_shell.adb_device:bulk_write(24): b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x10\x00\x00\x00K\x04\x00\x00\xbc\xb1\xa7\xb1' |
Hello, Jeff, i need help)
When i running my code:
An emulator is running on 5556 port.
I get an error
adb_shell.exceptions.InvalidCommandError: ('Unknown command: 72646e41', 1919184449, (543451503, 1936617283))
or something like this, I would like to know why this is happening.The text was updated successfully, but these errors were encountered: