python程序开发中,自己遇到的部分问题(持续更新。。。)

程序运行中遇到的问题总结:

1,Windows上运行程序报错:

from pyqt5 import qtcore, qtwidgets importerror: DLL load failed: 找不到指定的程序

解决:不要使用pip安装pyqt5,使用exe文件安装,安装时注意选择python文件路径,pyqt5下载链接:https://sourceforge.net/projects/pyqt/ 

2,Windows运行时,python程序报错:

connectionabortederror winerror 10053您的主机中的软件中止了一个已建立的连接

 尚未解决,目前猜测是电脑系统中某个软件的问题,因为有电脑中可以使用,也猜测是python环境问题

3,程序运行报错

SyntaxError: Non-UTF-8 code starting with '\xe5' in file /Users/tiger007/Desktop/shell_test/Data/flask_up_down/flask_up/save_gmv.py on line 159, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details,错误原因:程序中插入中文后的编码问题
解决方法:在程序开始加入下面一句话
# -*- coding: utf-8 -*-

4,用pyinstaller打包出来的exe,运行报错

failed to execute script main

待解决,哈哈

5,

XPCOMGlueLoad error for file /root/firefox/libxul.so:
libXt.so.6: cannot open shared object file: No such file or directory
Couldn’t load XPCOM.

 解决:

yum provides libXt.so.6
yum -y install libXt.x86_64

6, selenium xpath定位元素时出现如下错误信息(注意:之前切换到了iframe):

selenium.common.exceptions.WebDriverException: Message: TypeError: can't access dead object

原因:原因是代中用到了frame,获取元素前需要切换到frame才能定位到元素,否无法定位到元素

解决:在查找之前加一句:driver.switch_to_default_content() 退出frame

7,selenium 准备点击退出时,报错:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a class="ebase-frame-header-userLink" href="https://login.taobao.com/member/logout.jhtml?f=top&redirectURL=https://sycm.taobao.com/portal/home.htm"> is not clickable at point (1274,41.66667175292969) because another element <div class="ebase-ImageTips__dsImageTips "> obscures it

错误原因:现错误是因屏幕上出另一个具有相同或相同xpath / css的元素。 尝试给出一些等待方法,直到元素出现如Thread.sleep()wait() 

解决:两种方法

# 1
element = driver.find_element_by_css('div[class*="ebase-ImageTips__dsImageTips "]')
driver.execute_script("arguments[0].click();", element)
# 2
element = driver.find_element_by_css('div[class*=" ebase-ImageTips__dsImageTips "]')
webdriver.ActionChains(driver).move_to_element(element ).click(element ).perform()

 8,查看Linux系统位数

命令:arch

i686是32位,x86_64位64位

9,在centos7,无界面上运行headless Chrome 遇到报错 

Message: unknown error: Chrome failed to start: exited abnormally   (unknown error: DevToolsActivePort file doesn't exist)   (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

解决方法:添加参数chrome_options.add_argument('--no-sandbox')

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('user-agent=%s' % random.choice(MY_USER_AGENT_PC))
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', chrome_options=chrome_options)
driver.set_window_size(1366, 1000)  # 调整页面尺寸
driver.implicitly_wait(3)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值