Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Protocol: AttributeError: 'NoneType' object has no attribute 'ReadUntilClose' #59

Closed

Description

@eismog

Hi,

I will get an error, when I run two error command:

Like this:

import os.path as op

from adb import adb_commands
from adb import sign_m2crypto


# KitKat+ devices require authentication
signer = sign_m2crypto.M2CryptoSigner(
    op.expanduser('~/.android/adbkey'))
# Connect to the device
device = adb_commands.AdbCommands.ConnectDevice(
    rsa_keys=[signer])
# Now we can use Shell, Pull, Push, etc!
# for i in xrange(10):
#   print device.Shell('echo %d' % i)

print device.Shell('ls 333')
print device.Shell('ls 222')
print device.Shell('ls 111')
device.Close()

result:

/usr/bin/python2.7 /home/ligf/PycharmProjects/test-adb/tmp.py
ls: 333: No such file or directory
Traceback (most recent call last):

  File "/home/ligf/PycharmProjects/test-adb/tmp.py", line 18, in <module>
    print device.Shell('ls 222')
  File "build/bdist.linux-x86_64/egg/adb/adb_commands.py", line 227, in Shell
  File "build/bdist.linux-x86_64/egg/adb/adb_protocol.py", line 377, in Command
  File "build/bdist.linux-x86_64/egg/adb/adb_protocol.py", line 405, in StreamingCommand
AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'

Process finished with exit code 1

It may be a bug at here:
adb_protocol.py

    if cmd == b'CLSE':
      # Device doesn't support this service.
      return None
    if cmd != b'OKAY':
      raise InvalidCommandError('Expected a ready response, got %s' % cmd,
                                cmd, (remote_id, their_local_id))
    return _AdbConnection(usb, local_id, remote_id, timeout_ms)

BRs
/Eismog

Activity

  1. myrfy001 commented on Oct 13, 2017

    @myrfy001

    The same problem. Has it been solved?

    My phone is Huawei Honor 8.

  2. fahhem commented on Oct 13, 2017

    @fahhem
    Contributor

    Can you add this between line 253 and 254 of adb/adb_protocol.py: print command

    Then run it again and paste the output here, please. This should only be happening if the device is either sending two CLSE responses or the library isn't handling the first CLSE in time.

  3. myrfy001 commented on Oct 13, 2017

    @myrfy001

    Hi
    the print output is here. The number 0 is the output of the first loop, the item in buckets are the output of print(command, arg0, arg1, bytes(data))

    ('AUTH', 1, 0, '\r\xbf_\xa5]\xbdUi\xbc\x02\x10n\x8f\xe2\xf9p\x17I:Y')
    ('CNXN', 16777216, 4096, 'device::ro.product.name=FRD-AL00;ro.product.model=FRD-AL00;ro.product.device=HWFRD;features=cmd,shell_v2')
    ('OKAY', 8, 1, '')
    ('WRTE', 8, 1, '0\n')
    ('CLSE', 8, 1, '')
    0
    
    ('CLSE', 8, 1, '')
    Traceback (most recent call last):
      File "test.py", line 24, in <module>
        print device.Shell('echo %d' % i)
      File "build/bdist.macosx-10.12-x86_64/egg/adb/adb_commands.py", line 227, in Shell
      File "build/bdist.macosx-10.12-x86_64/egg/adb/adb_protocol.py", line 386, in Command
      File "build/bdist.macosx-10.12-x86_64/egg/adb/adb_protocol.py", line 414, in StreamingCommand
    AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'
    
  4. MohammadAG commented on Jan 22, 2018

    @MohammadAG
    Contributor

    This also seems to be a problem on an LG G6

    Here's the output of print:
    CNXN
    OKAY
    WRTE
    CLSE
    Traceback (most recent call last):
    File "//installer.py", line 129, in
    device.Shell("echo 2")
    File "build/bdist.macosx-10.13-intel/egg/adb/adb_commands.py", line 233, in Shell
    File "build/bdist.macosx-10.13-intel/egg/adb/adb_protocol.py", line 383, in Command
    File "build/bdist.macosx-10.13-intel/egg/adb/adb_protocol.py", line 411, in StreamingCommand
    AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'
    CLSE

    This fixes the issue (in the Open method), I'm not sure if it's the best fix though:

        if cmd == b'CLSE':
          # Some devices send two CLSEs
          cmd, remote_id, their_local_id, _ = cls.Read(usb, [b'CLSE', b'OKAY'],
                                                       timeout_ms=timeout_ms)
          # Device doesn't support this service.
          if cmd == b'CLSE':
            return None
    
  5. alxhoff commented on Feb 19, 2019

    @alxhoff

    I am still affected by this issue

    File "/usr/lib/python2.7/site-packages/adb/adb_commands.py", line 366, in Shell
    timeout_ms=timeout_ms)
    File "/usr/lib/python2.7/site-packages/adb/adb_protocol.py", line 406, in Command
    return ''.join(cls.StreamingCommand(usb, service, command, timeout_ms))
    File "/usr/lib/python2.7/site-packages/adb/adb_protocol.py", line 434, in StreamingCommand
    for data in connection.ReadUntilClose():
    AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'

    And my adb_protocol.py already contained

        if cmd == b'CLSE':
          # Some devices send two CLSEs
          cmd, remote_id, their_local_id, _ = cls.Read(usb, [b'CLSE', b'OKAY'],
                                                       timeout_ms=timeout_ms)
          # Device doesn't support this service.
          if cmd == b'CLSE':
            return None
    

    Any help would be greatly appreciated as it seems to fail randomly and during periods of high ADB traffic.

  6. alxhoff commented on Apr 2, 2019

    @alxhoff

    Bump. This is plaguing my app like nothing else.

  7. alxhoff commented on Apr 2, 2019

    @alxhoff

    After having a fresh google around PR #151 seems to of fixed it up.

  8. embray commented on Apr 7, 2019

    @embray

    @alxhoff Thanks for the confirmation. If Google loves open source so much it'd be great if they gave developers of their open-source projects the time necessary to review and merge bug fixes to them 😀 😀 😀
    For myself I'll probably be forced to distribute my own fork of this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions