最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【基本解决】uiautomator2初始化到安卓手机小米9中报错:http.client.RemoteDisconnected Remote end closed connection without response

uiautomator2 crifan 84浏览 0评论
折腾:
【未解决】给安卓手机小米9中欢乐大作战的游戏实现自动挂机
期间,在pipenv中去:
python -m uiautomator2 init
初始化uiautomator2到安卓手机小米9中,结果报错:
➜  autoTestAndroidGameHappyBigBattle python -m uiautomator2 init
[D 191119 22:05:39 init:109] Initial device AdbDevice(serial=8c8a4d4d)
[I 191119 22:05:39 init:277] Install minicap, minitouch
[D 191119 22:05:39 init:51] Download https://tool.appetizer.io/openatx/stf-binaries/raw/master/node_modules/minitouch-prebuilt/prebuilt/arm64-v8a/bin/minitouch
minitouch |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 33.9K/33.9K
[D 191119 22:05:40 init:186] Push to /data/local/tmp/minitouch:0755
[I 191119 22:05:40 init:283] Android Q (sdk:29) has no minicap resource
[D 191119 22:05:40 init:51] Download https://tool.appetizer.io/openatx/android-uiautomator-jsonrpcserver/releases/download/v0.1.6/bundle.jar
bundle.jar |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 450.6K/450.6K
[D 191119 22:05:40 init:186] Push to /data/local/tmp/bundle.jar:0644
[D 191119 22:05:40 init:51] Download https://tool.appetizer.io/openatx/android-uiautomator-jsonrpcserver/releases/download/v0.1.6/uiautomator-stub.jar
uiautomator-stub.jar |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 33.2K/33.2K
[D 191119 22:05:40 init:186] Push to /data/local/tmp/uiautomator-stub.jar:0644
[I 191119 22:05:40 init:292] Install com.github.uiautomator, com.github.uiautomator.test 2.0.3
[D 191119 22:05:40 init:112] Shell: ('pm', 'uninstall', 'com.github.uiautomator')
[D 191119 22:05:40 init:112] Shell: ('pm', 'uninstall', 'com.github.uiautomator.test')
[D 191119 22:05:41 init:51] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.0.3/app-uiautomator.apk
app-uiautomator.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 1.7M/1.7M
[D 191119 22:05:41 init:186] Push to /data/local/tmp/app-uiautomator.apk:0644
[D 191119 22:05:41 init:112] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator.apk')
[D 191119 22:05:52 init:51] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.0.3/app-uiautomator-test.apk
app-uiautomator-test.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 1.2M/1.2M
[D 191119 22:05:53 init:186] Push to /data/local/tmp/app-uiautomator-test.apk:0644
[D 191119 22:05:53 init:112] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator-test.apk')
[D 191119 22:05:57 init:214] Real version: [0, 7, 4], Expect version: [0, 7, 4]
[I 191119 22:05:57 init:300] Check install
[D 191119 22:05:57 init:310] Forward: local:tcp:58678 -> remote:tcp:7912
...
[D 191119 22:06:02 init:310] Forward: local:tcp:58678 -> remote:tcp:7912
Traceback (most recent call last):
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1321, in getresponse
    response.begin()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 265, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1321, in getresponse
    response.begin()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 265, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/__main__.py", line 229, in <module>
    main()
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/__main__.py", line 219, in main
    actions[args.subparser](args)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/__main__.py", line 34, in cmd_init
    init.install(args.server)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/init.py", line 301, in install
    self.check_atx_agent_version()
  File "</Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/decorator.py:decorator-gen-4>", line 2, in check_atx_agent_version
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/retry/api.py", line 74, in retry_decorator
    logger)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/retry/api.py", line 33, in __retry_internal
    return f()
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/init.py", line 311, in check_atx_agent_version
    version = requests.get("http://127.0.0.1:%d/version" % port).text.strip()
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
http.client.RemoteDisconnected: Remote end closed connection without response
uiautomator2 http.client.RemoteDisconnected: Remote end closed connection without response
处理uiautomator2电脑和手机连接不上的问题:(‘Connection aborted.’, RemoteDisconnected(‘Remote end closed connecti… – 简书
Appium-Python: find_element_by_id intermittently produces ‘Connection aborted.’ error · Issue #437 · appium/python-client
python -m uiautomator2 init 10.0.1.1:8000 报错 · Issue #14 · openatx-archive/atx-server
开启两个 appium 端口为何同时使用会报 http.client.RemoteDisconnected: Remote end closed connection without response? · TesterHome
python – Selenium – http.client.RemoteDisconnected: Remote end closed connection without response – Stack Overflow
再去运行一次试试:
python -m uiautomator2 init
结果:
问题依旧:
➜  autoTestAndroidGameHappyBigBattle python -m uiautomator2 init
[D 191119 22:12:01 init:109] Initial device AdbDevice(serial=8c8a4d4d)
[I 191119 22:12:01 init:277] Install minicap, minitouch
[D 191119 22:12:01 init:48] Use cached assets: /Users/crifan/.uiautomator2/40b57fb8db0d9cc9349fd77248111576dad7e945698260536c6594fc/minitouch
[D 191119 22:12:01 init:186] Push to /data/local/tmp/minitouch:0755
[I 191119 22:12:01 init:283] Android Q (sdk:29) has no minicap resource
[D 191119 22:12:01 init:48] Use cached assets: /Users/crifan/.uiautomator2/6edef50a02af79ddf2217874d1ce621d4a847d6762dc86c10d5811a0/bundle.jar
[D 191119 22:12:01 init:186] Push to /data/local/tmp/bundle.jar:0644
[D 191119 22:12:01 init:48] Use cached assets: /Users/crifan/.uiautomator2/42a21461fa2b0031646c206175ef315ae8a142421a7675e219336bca/uiautomator-stub.jar
[D 191119 22:12:01 init:186] Push to /data/local/tmp/uiautomator-stub.jar:0644
[I 191119 22:12:01 init:295] Already installed com.github.uiautomator apks
[D 191119 22:12:01 init:214] Real version: [0, 7, 4], Expect version: [0, 7, 4]
[I 191119 22:12:01 init:300] Check install
[D 191119 22:12:01 init:310] Forward: local:tcp:58678 -> remote:tcp:7912
。。。
[D 191119 22:12:05 init:310] Forward: local:tcp:58678 -> remote:tcp:7912
Traceback (most recent call last):
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1321, in getresponse
    response.begin()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 265, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response


During handling of the above exception, another exception occurred:

...
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
然后开发者选项中USB调试也都开启过了:
注意到此时安卓小米9中已安装了ATX
去打开ATX看看
打开后提示要权限,全部都给:
看到主界面了:
结果遇到:
【未解决】小米9中ATX启动UIAUTOMATOR失败:ATX Uiautomator not starting
看到上面地址写的是:
192.168.31.17
Mac中Safari打开192.168.31.17,无法打开。
ATX:Uiautomator not starting
权限问题 · Issue #11 · openatx/atx-agent
mac中试试
➜  ~ curl -X GET 192.168.31.17/version
curl: (7) Failed to connect to 192.168.31.17 port 80: Connection refused
➜  ~ curl -X GET 192.168.31.17:7912/version
curl: (7) Failed to connect to 192.168.31.17 port 7912: Connection refused
关于uiautomator2.UiaError · Issue #2 · openatx/uiautomator2
uiautomator2 RemoteDisconnected Remote end closed connection without response
Remote end closed connection without response on successive Session requests · Issue #4784 · psf/requests
lengyao (闪耀之冷) · 回帖 · TesterHome
Help: This script can’t run anymore, I don’t know why. – Programmer Sought
突然想到:或许不需要解决,后续可以正常使用uiautomator2?
去看log,可以定位到代码:
/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/init.py
    def check_atx_agent_version(self):
        port = self._device.forward_port(7912)
        self.logger.debug("Forward: local:tcp:%d -> remote:tcp:%d", port, 7912)
        version = requests.get("http://127.0.0.1:%d/version" % port).text.strip()
        self.logger.debug("atx-agent version %s", version)
mac中试试:
➜  ~ curl -X GET 127.0.0.1:7912/version
curl: (7) Failed to connect to 127.0.0.1 port 7912: Connection refused
➜  ~ curl -X GET http://127.0.0.1:7912/version
curl: (7) Failed to connect to 127.0.0.1 port 7912: Connection refused
都连不上
感觉是:
前提需要mac本地运行命令才对
但是此处明显mac中什么都没运行啊
怎么可能有服务运行
Developers – ATX-agent interrupted. –
说是需要2个apk
app-uiautomator.apk
app-uiautomator-test.apk
求助:这样的脚本已经无法运行下去,不知为何 / jeepxie.net
http://www.jeepxie.net/article/234692.html
https://github.com/openatx/atx-agent/issues/11
am startservice --user -2 -n com.github.uiautomator/.Service
去mac中运行上面命令试试?
➜  ~ am startservice --user -2 -n com.github.uiautomator/.Service
zsh: command not found: am
看到:
curl -X POST -d command="am startservice -n com.github.uiautomator/.Service" http://10.0.100.228:7912/shell
-》说明am应该在手机端运行
去mac中ping安卓端
➜  ~ ping 192.168.31.17
PING 192.168.31.17 (192.168.31.17): 56 data bytes
64 bytes from 192.168.31.17: icmp_seq=0 ttl=64 time=4.429 ms
64 bytes from 192.168.31.17: icmp_seq=1 ttl=64 time=26.364 ms
是通的。
抽空去看看
https://github.com/xiaocong/uiautomator
提到的:
Manual Init · openatx/uiautomator2 Wiki
再去试了试:
python -m uiautomator2 init
最后都是在
[I 191120 19:54:54 init:300] Check install
然后多次:
[D 191120 19:54:54 init:310] Forward: local:tcp:60660 -> remote:tcp:7912
之后,报错了。
再去看代码,是:
/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/urllib3/connectionpool.py
            # Make the request on the httplib connection object.
            httplib_response = self._make_request(
                conn,
                method,
                url,
                timeout=timeout_obj,
                body=body,
                headers=headers,
                chunked=chunked,
            )
然后底层最终
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py
            # Presumably, the server closed the connection before
            # sending a valid response.
            raise RemoteDisconnected("Remote end closed connection without"
                                     " response")
而报错的。
看来就是尝试去连接,结果连不上
那就看看去连接哪个地址
看来就是和
Forward: local:tcp:60660 -> remote:tcp:7912
相关的连接
加上调试:
  # for debug
  print("conn=%s,method=%s,url=%s,timeout_obj=%s,body=%s,headers=%s,chunked=%s" % \
                (conn, method, url, timeout_obj, body, headers, chunked))
结果:
[D 191120 20:04:30 init:310] Forward: local:tcp:60660 -> remote:tcp:7912
conn=<urllib3.connection.HTTPConnection object at 0x108ad5c50>,method=GET,url=/version,timeout_obj=Timeout(connect=None, read=None, total=None),body=None,headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'},chunked=False
但是还是不知道谁去连接了谁
搜:Check install
找到:
/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/init.py
self.logger.info("Check install")
self.check_atx_agent_version()
print("Successfully init %s" % self._device)
去看看:check_atx_agent_version
    def check_atx_agent_version(self):
        port = self._device.forward_port(7912)
        self.logger.debug("Forward: local:tcp:%d -> remote:tcp:%d", port, 7912)
        version = requests.get("http://127.0.0.1:%d/version" % port).text.strip()
        self.logger.debug("atx-agent version %s", version)
果然是这个version
加上调试信息,确认一下:
# version = requests.get("http://127.0.0.1:%d/version" % port).text.strip()
versionUrl = "http://127.0.0.1:%d/version" % port
print("versionUrl=%s" % versionUrl)
连接的是:
versionUrl=http://127.0.0.1:60660/version
那问题就来了:
为何mac本地此处是否有运行起来对应的服务,供你访问http接口
Developers – ATX-agent interrupted. –
和我问题一样
注意到
    def check_atx_agent_version(self):
        port = self._device.forward_port(7912)
其中会先去forward_port 转发端口
会不会是转发端口失败?
check_atx_agent_version fail
uiautomator2 forward_port
uiautomator2源码解析 – 简书
此处
http://127.0.0.1:60660/version
肯定会报错:
因为没有服务在运行
Merge branch ‘master’ into pure-python-adb · 6e31679522 – uiautomator2 – Gitea: Git with a cup of tea
uiautomator2/__main__.py
    def check_agent_installed(self, agent_version):
        lport = self.forward_port(7912)
        log.debug("forward device(port:7912) -> %d", lport)
        try:
            r = requests.get("http://127.0.0.1:%d/version" % lport, timeout=5)
            return r.text.strip() == agent_version
        except:
            return False
uiautomator2 init 出现 FAIL 0014 错误 · Issue #305 · openatx/uiautomator2
从一个Uiautomator的官方demo说源码 – saii的专栏 – CSDN博客
def connect_usb(serial=None):
。。。
    adb = adbutils.Adb(serial)
    lport = adb.forward_port(7912)
    d = connect_wifi('127.0.0.1:' + str(lport))
 那干脆此处:
直接运行代码usb连接试试
➜  autoTestAndroidGameHappyBigBattle python
Python 3.7.3 (default, May 22 2019, 10:55:14) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import uiautomator2 as u2
>>> d = u2.connect('8c8a4d4d')
conn=<urllib3.connection.HTTPConnection object at 0x1077f4da0>,method=GET,url=/version,timeout_obj=Timeout(connect=2, read=2, total=None),body=None,headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'},chunked=False
报同样错误
UiautoMator2源码分析 – DLUT_WJX的博客 – CSDN博客
基于 ATX-Server 的 UI 自动化测试框架 · TesterHome
感觉是:
需要手机中去安装ATX及相关内容?
并且确保Uiautomator2正常运行才对
此处应该就是手机中Uiautomator2没有正常运行 有关系
在:
【未解决】小米9中ATX启动UIAUTOMATOR失败:ATX Uiautomator not starting
期间,无意间发现可以启动了:
ATX: Uiautomator started
所以再去试试init:
➜  autoTestAndroidGameHappyBigBattle python -m uiautomator2 init
[D 191120 20:25:07 init:109] Initial device AdbDevice(serial=8c8a4d4d)
[I 191120 20:25:07 init:277] Install minicap, minitouch
[D 191120 20:25:07 init:48] Use cached assets: /Users/crifan/.uiautomator2/40b57fb8db0d9cc9349fd77248111576dad7e945698260536c6594fc/minitouch
[D 191120 20:25:07 init:186] Push to /data/local/tmp/minitouch:0755
[I 191120 20:25:07 init:283] Android Q (sdk:29) has no minicap resource
[D 191120 20:25:07 init:48] Use cached assets: /Users/crifan/.uiautomator2/6edef50a02af79ddf2217874d1ce621d4a847d6762dc86c10d5811a0/bundle.jar
[D 191120 20:25:07 init:186] Push to /data/local/tmp/bundle.jar:0644
[D 191120 20:25:07 init:48] Use cached assets: /Users/crifan/.uiautomator2/42a21461fa2b0031646c206175ef315ae8a142421a7675e219336bca/uiautomator-stub.jar
[D 191120 20:25:07 init:186] Push to /data/local/tmp/uiautomator-stub.jar:0644
[I 191120 20:25:07 init:295] Already installed com.github.uiautomator apks
[D 191120 20:25:07 init:214] Real version: [0, 7, 4], Expect version: [0, 7, 4]
[I 191120 20:25:07 init:300] Check install
[D 191120 20:25:07 init:310] Forward: local:tcp:60660 -> remote:tcp:7912
versionUrl=http://127.0.0.1:60660/version
conn=<urllib3.connection.HTTPConnection object at 0x1097ee0f0>,method=GET,url=/version,timeout_obj=Timeout(connect=None, read=None, total=None),body=None,headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'},chunked=False
[D 191120 20:25:07 init:315] atx-agent version 0.7.4
Successfully init AdbDevice(serial=8c8a4d4d)
真的可以正常初始化了。
但是usb连接貌似还是报错:
>>> import uiautomator2 as u2
>>> d = u2.connect('8c8a4d4d')
conn=<urllib3.connection.HTTPConnection object at 0x1077f4588>,method=GET,url=/version,timeout_obj=Timeout(connect=2, read=2, total=None),body=None,headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'},chunked=False
conn=<urllib3.connection.HTTPConnection object at 0x1077f4be0>,method=GET,url=/version,timeout_obj=Timeout(connect=2, read=2, total=None),body=None,headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'},chunked=False
conn=<urllib3.connection.HTTPConnection object at 0x1077f4be0>,method=POST,url=/jsonrpc/0,timeout_obj=Timeout(connect=2, read=2, total=None),body={"jsonrpc": "2.0", "id": 1, "method": "deviceInfo"},headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '51'},chunked=False
突然发现,貌似上述是log,不是错误,应该再去:
print(d.info)
才对。
中间又出现过ATX无法启动uiautomator的
但是最后,经过几次尝试,竟然连接上了:
>>> import uiautomator2 as u2
>>> d = u2.connect('8c8a4d4d')
conn=<urllib3.connection.HTTPConnection object at 0x1078b40b8>,method=GET,url=/version,timeout_obj=Timeout(connect=2, read=2, total=None),body=None,headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'},chunked=False
...
conn=<urllib3.connection.HTTPConnection object at 0x1078ab588>,method=GET,url=/version,timeout_obj=Timeout(connect=2, read=2, total=None),body=None,headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'},chunked=False
>>> print(d.info)
conn=<urllib3.connection.HTTPConnection object at 0x1078ab588>,method=POST,url=/jsonrpc/0,timeout_obj=Timeout(connect=60, read=60, total=None),body=b'{"jsonrpc": "2.0", "id": "620310ab32067da976a5f2fdf327da94", "method": "deviceInfo", "params": {}}',headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Content-Length': '98'},chunked=False
/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/__init__.py:462: RuntimeWarning: uiautomator2 is not reponding, restart uiautomator2 automatically
  stacklevel=1)
conn=<urllib3.connection.HTTPConnection object at 0x1078ab588>,method=POST,url=/jsonrpc/0,timeout_obj=Timeout(connect=2, read=2, total=None),body={"jsonrpc": "2.0", "id": 1, "method": "deviceInfo"},headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '51'},chunked=False
[D 191120 21:17:10 __init__:639] force reset uiautomator
...
[D 191120 21:17:10 __init__:655] uiautomator(1.0) is starting ...
...
[D 191120 21:17:11 __init__:655] uiautomator(1.0) is starting ...
...
[I 191120 21:17:12 __init__:643] uiautomator back to normal
conn=<urllib3.connection.HTTPConnection object at 0x1078ab588>,method=POST,url=/jsonrpc/0,timeout_obj=Timeout(connect=60, read=60, total=None),body=b'{"jsonrpc": "2.0", "id": "dea4a81ba7c095551ccadd0fe17d7836", "method": "deviceInfo", "params": {}}',headers={'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Content-Length': '98'},chunked=False
{'currentPackageName': 'com.github.uiautomator', 'displayHeight': 2135, 'displayRotation': 0, 'displaySizeDpX': 393, 'displaySizeDpY': 851, 'displayWidth': 1080, 'productName': 'cepheus', 'sdkInt': 29, 'naturalOrientation': True}
>>> 
即:
import uiautomator2 as u2
d = u2.connect('8c8a4d4d')
print(d.info)
(在多次尝试后终于连上了,然后)输出了设备信息:
{'currentPackageName': 'com.github.uiautomator', 'displayHeight': 2135, 'displayRotation': 0, 'displaySizeDpX': 393, 'displaySizeDpY': 851, 'displayWidth': 1080, 'productName': 'cepheus', 'sdkInt': 29, 'naturalOrientation': True}
了。
【部分解决】小米9中ATX启动UIAUTOMATOR失败:ATX Uiautomator not starting
至此,算是解决问题了。
【总结】
之前
python -m uiautomator2 init
在初始化安装一些安装包
后,结果就会报错:
[I 191119 22:05:57 init:300] Check install
[D 191119 22:05:57 init:310] Forward: local:tcp:58678 -> remote:tcp:7912
....
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/init.py", line 311, in check_atx_agent_version
    version = requests.get("http://127.0.0.1:%d/version" % port).text.strip()
...
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
原因:
手机中的uiautomator服务没有启动。
解决办法:
去手机中启动uiautomator服务。
具体步骤:
打开手机中已安装的ATX,点击
启动UIAUTOMATOR
  • 正常的话:会显示个toast:ATX: Uiautomator started
  • 不正常的话,会显示toast:ATX:Uiautomator not starting
    • 如果这样,如何解决?
      • 参考:
        • 【部分解决】小米9中ATX启动UIAUTOMATOR失败:ATX Uiautomator not starting
      • 但是也不确定根本原因
      • 暂时只能尝试的去
        • 给ATX和com.github.uiautomator.test所有权限都允许
        • 多试试几次
          • 估计就可以了。

转载请注明:在路上 » 【基本解决】uiautomator2初始化到安卓手机小米9中报错:http.client.RemoteDisconnected Remote end closed connection without response

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
16 queries in 0.097 seconds, using 9.41MB memory