Pycharm报错:ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

一、场景回溯:

环境:夜神模拟器+Appium+Python

打开Pycharm,直接执行脚本:

# coding:utf-8
from appium import webdriver
# desired_caps = {}
desired_caps = dict()
desired_caps['platformName'] = "Android"         # 声明是ios还是Android系统
desired_caps['platformVersion'] = '5.1.1'        # Android内核版本号,可以在夜神模拟器设置中查看
desired_caps['deviceName'] = '127.0.0.1:62001'   # 连接的设备名称
desired_caps['appname'] = 'kaoyan3.1.0.apk'
desired_caps['noReset'] = 'False'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'
desired_caps['appPackage'] = 'com.tal.kaoyan'    # apk的包名
desired_caps['appActivity'] = 'com.tal.kaoyan.ui.activity.SplashActivity'  # apk的launcherActivity
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)          # 建立 session
print('execute success!')
driver.quit()      # 退出 session

报错:

platform win32 -- Python 3.7.4, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: E:\MyDOC\Git\AppiumProj\test_case
test_demo.py:None (test_demo.py)
……(省略若干报错)……
C:\Python37\lib\urllib3\util\connection.py:70: in create_connection
    sock.connect(sa)
E   ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:
……(省略若干报错)……
E   urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:……(省略若干报错)……

二、问题解决:

1、打开夜神模拟器,安装对应的app(kaoyan3.1.0.apk):

安装方式:

(1)直接拖入夜神模拟器;

(2)在夜神模拟器添加本地apk;

(3)在夜神模拟器的应用商城进行下载;

2、快捷键“win+r”打开cmd,输入appium:

C:\Users\Administrator>appium
[Appium] Welcome to Appium v1.14.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

ok啦~

你可能感兴趣的:(Appium)