0

当我发出 device.takeSnapshot() 命令和 device.touch() 命令时出现此错误:

    Traceback (most recent call last):
  File "C:\Users\Me\Desktop\AndroidViewClient_Bots\pytesser\insta_get_list_of
_users.py", line 82, in <module>
    device.touch(213,481, 'DOWN_AND_UP')
  File "C:\Python27\lib\site-packages\androidviewclient-7.0.2-py2.7.egg\com\dtmi
lano\android\adb\adbclient.py", line 425, in touch
    self.shell('input tap %d %d' % (x, y))
  File "C:\Python27\lib\site-packages\androidviewclient-7.0.2-py2.7.egg\com\dtmi
lano\android\adb\adbclient.py", line 257, in shell
    self.__send('shell:%s' % cmd, checkok=True, reconnect=False)
  File "C:\Python27\lib\site-packages\androidviewclient-7.0.2-py2.7.egg\com\dtmi
lano\android\adb\adbclient.py", line 154, in __send
    self.__checkOk()
  File "C:\Python27\lib\site-packages\androidviewclient-7.0.2-py2.7.egg\com\dtmi
lano\android\adb\adbclient.py", line 184, in __checkOk
    recv = self.socket.recv(4)
socket.error: [Errno 10053] An established connection was aborted by the softwar
e in your host machine

这是我的代码:

import sys
import os
import time
from PIL import Image # Python Image Library

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.adb.adbclient import AdbClient, Device
from com.dtmilano.android.viewclient import ViewClient, View


device, serialno = ViewClient.connectToDeviceOrExit(verbose=True)


my_img = device.takeSnapshot()
device.touch(200,300, 'DOWN_AND_UP')

这真的很奇怪,因为如果我只有

my_img = device.takeSnapshot() 

或者

device.touch(200,300, 'DOWN_AND_UP')

然后我没有错误。但是,在相同的代码中,它会生成上述错误。发出多个设备命令时有什么我没有做的吗?

4

1 回答 1

1

我猜这有点棘手。您的问题可能来自device.takeSnapshot()定义为

def takeSnapshot(self, reconnect=False):
    '''
    Takes a snapshot of the device and return it as a PIL Image.
    '''

    ...

因此,如果您打算在拍摄快照后继续使用连接,请使用

device.takeSnapshot(reconnect=True)
于 2014-05-30T20:57:41.013 回答