python跳过异常继续执行执行报错: ConnectionRefusedError:怎么解决?

一、场景回溯:环境:夜神模拟器+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('
}
Anaconda的JupyterLab 作为优秀的网页编辑器,非常适用于编写Python程序,但往往可能因一些原因如
JupyterLab报错:Server Connection Error,而无法正常连接服务器,为此我整理了以下方法,以解决该问题。
一、报错情形JupyterLab报错:Server Connection Error: A connection to the jupyter server could not be established. Jupyterlab will continue trying to reconnect. Check your network connection or jupyter server.服务器连接错误:jupyter服务器无法建立连接。木星实验室将继续尝试重新连接。检查您的网络连接或jupyter服务器。在此情况下,无法使用Python,无法进行编译,时常弹出错误,无法连接!二、深层原因使用微软账号登陆windows后,用户名称中存在中文名,导致jupyter路径中含有中文,无法识别路径。三、解决方案解决办法:(以Win10为例) 将用户名修改为英文,问题解决!以下介绍修改用户名的方式:3.1 重命名用户名右键【计算机】->【管理】->【本地用户和组】->【用户】->右键【中文用户名】->【重命名】3.2 启用Administrator账户Win10默认将Administrator账户禁用,在此需要启用Administrator账户,方法如下:在上步继续,右键【Administrator】->【属性】->取消勾选【账户已禁用】3.3 切换Administrator账户注销当前账户:【Windows+X】-【注销】重启电脑切换到Administrator账户登录3.4 重命名用户文件夹进入C:\用户\xxx,找到以中文用户名命名的文件夹,重命名为英文,不建议使用空格3.5 修改注册表打开Windows注册表管理器:【Windows+R】->【运行】->输入regedit依次展开HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Profilelist,在Profilelist下的文件夹对应系统中用户,而文件夹中ProfileImagePath值是指向每个用户文件夹的地址,一个个点击查看,找到中文名用户的对应所在的ProfileImagePath值修改ProfileImagePath的值,将地址改为修改成英文的文件夹名,要与C盘的文件夹名一致再次注销,完成登录用户文件夹名更改重新登录,以修改后用户名后的账户3.6 修改环境变量打开【控制面板】-【系统和安全】-【系统】-【高级系统设置】-【环境变量】将用户变量和系统变量中,所有含原用户名的字符修改为当前用户名打开Anaconda的JupyterLab,配置Python,连接成功,可以正常编辑解释代码,问题已解决!小结在创建Windows用户或新建文件夹时,习惯使用英文命名,将避免很多不必要的麻烦!}
我有一个问题:我想测试"select"和"input"。我能像下面的代码那样写吗:原始代码:12 class Sinaselecttest(unittest.TestCase):
13
14
def setUp(self):
15
binary = FirefoxBinary('/usr/local/firefox/firefox')
16
self.driver = webdriver.Firefox(firefox_binary=binary)
17
18
def test_select_in_sina(self):
19
driver = self.driver
20
driver.get("https://www.sina.com.cn/")
21
try:
22
WebDriverWait(driver,30).until(
23
ec.visibility_of_element_located((By.XPATH,"/html/body/div[9]/div/div[1]/form/div[3]/input"))
24
)
25
finally:
26
driver.quit()
# #测试select功能
27
select=Select(driver.find_element_by_xpath("//*[@id='slt_01']")).select_by_value("微博")
28
element=driver.find_element_by_xpath("/html/body/div[9]/div/div[1]/form/div[3]/input")
29
element.send_keys("杨幂")
30
driver.find_element_by_xpath("/html/body/div[9]/div/div[1]/form/input").click()
31
driver.implicitly_wait(5)
32
def tearDown(self):
33
self.driver.close()我想测试Selenium "选择" www.example.com我选择新浪网站选择一个选项,并在textarea中输入文本。然后搜索它。但当我运行此测试时,它有错误:function.so I choose sina website to select one option and input text in textarea.then search it .but when I run this test,it has error:Traceback (most recent call last):
File "test_sina_select.py", line 32, in tearDown
self.driver.close()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 688, in close
self.execute(Command.CLOSE)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 376, in execute
return self._request(command_info[0], url, body=data)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 399, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 68, in request
**urlopen_kw)
File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 81, in request_encode_url
return self.urlopen(method, url, **urlopen_kw)
File "/usr/lib/python2.7/site-packages/urllib3/poolmanager.py", line 247, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 597, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python2.7/site-packages/urllib3/util/retry.py", line 271, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=51379): Max retries exceeded with url: /session/2e64d2a1-3c7f-4221-96fe-9d0b1c102195/window (Caused by ProtocolError('Connection aborted.', error(111, 'Connection refused')))
----------------------------------------------------------------------
Ran 1 test in 72.106s谁能告诉我为什么?谢谢}

我要回帖

更多关于 python跳过异常继续执行 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信