openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.38k stars 1.37k forks source link

使用uiautormator2,报错UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 38: invalid start byte #901

Closed tody-yang closed 3 months ago

tody-yang commented 1 year ago

image

代码:

def buildup_dev(serial_no):

    util.exec_cmd("adb -s {} shell setenforce 0".format(serial_no))  # 临时打开se linux权限 
    try_cnt = 0

    while True:
        if ConnectDevice.dev is not '' and ConnectDevice.dev.serial is not None:
            print("RUN buildup_dev, ConnectDevice.dev is not NONE")
            ConnectDevice.dev.healthcheck()
            break

        try_cnt = try_cnt + 1
        if try_cnt > 3:
            break

        try:
            logging.info("%d connect usb..." % try_cnt)
            ConnectDevice.dev = connect_usb(serial_no)
            ConnectDevice.dev.healthcheck()
            ctx = ConnectDevice.dev.watch_context()
            ctx.when('ALLOW').click()
            ctx.when('GOT IT').click()
            ctx.when('ADD AUTOMATICALLY').click()
            ctx.when('NEXT').click()
            ctx.when('AGREE').click()
            ctx.when('START').click()
            ctx.when('Close app').click()
        except Exception as f:
            ConnectDevice.dev == ''
            logging.error("connect uiautomator fail %d" % try_cnt)
            print(f)
            traceback.print_exc()
tody-yang commented 1 year ago

我看了下healthcheck()函数好像是弃用的了,那我注释掉之后,就很容易报错 if res.status_code == 502:

      raise GatewayError(

res, "gateway error, time used %.1fs" % (time.time() - request_start)) E uiautomator2.exceptions.GatewayError: (<Response [502]>, 'gateway error, time used 0.4s') 我该怎么修改,或者说有什么新方法替代healthcheck()

codeskyblue commented 3 months ago

对的以及移除,可以用 d.start_uiautomator()代替