如果您想了解IOError:[Errno32]管道损坏:Python的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析Cygwin上使用Python3.7的Flask/Werkzeug:Bloc
如果您想了解IOError:[Errno 32]管道损坏:Python的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析Cygwin上使用Python 3.7的Flask / Werkzeug:BlockingIOError:[Errno 11]资源暂时不可用、FileExistsError:[Errno 17] 文件存在:python3 中的“2021-07-31_1044”、IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log、IOError:[Errno 22]无效模式('r')或文件名:'c:\ Python27 test.txt'的各个方面,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- IOError:[Errno 32]管道损坏:Python
- Cygwin上使用Python 3.7的Flask / Werkzeug:BlockingIOError:[Errno 11]资源暂时不可用
- FileExistsError:[Errno 17] 文件存在:python3 中的“2021-07-31_1044”
- IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log
- IOError:[Errno 22]无效模式('r')或文件名:'c:\ Python27 test.txt'
IOError:[Errno 32]管道损坏:Python
我有一个非常简单的Python 3脚本:
f1 = open(''a.txt'', ''r'')print(f1.readlines())f2 = open(''b.txt'', ''r'')print(f2.readlines())f3 = open(''c.txt'', ''r'')print(f3.readlines())f4 = open(''d.txt'', ''r'')print(f4.readlines())f1.close()f2.close()f3.close()f4.close()
但它总是说:
IOError: [Errno 32] Broken pipe
我在网上看到了解决此问题的所有复杂方法,但是我直接复制了此代码,因此我认为代码有问题,而不是Python的SIGPIPE。
我正在重定向输出,因此,如果上面的脚本被命名为“ open.py”,那么我要运行的命令将是:
open.py | othercommand
答案1
小编典典我没有重现这个问题,但是也许这种方法可以解决这个问题:(逐行写入stdout
而不是使用print
)
import syswith open(''a.txt'', ''r'') as f1: for line in f1: sys.stdout.write(line)
你能抓住破损的管道吗?这将文件stdout
逐行写入,直到关闭管道为止。
import sys, errnotry: with open(''a.txt'', ''r'') as f1: for line in f1: sys.stdout.write(line)except IOError as e: if e.errno == errno.EPIPE: # Handle error
您还需要确保othercommand
在管道变得太大之前正在从管道读取-https:
//unix.stackexchange.com/questions/11946/how-big-is-the-pipe-
buffer
Cygwin上使用Python 3.7的Flask / Werkzeug:BlockingIOError:[Errno 11]资源暂时不可用
在正确的Cygwin安装中,共享库始终在比fork失败的情况下更高的地址上运行。
要查看预期范围,可以查看基址数据库。
在我当前的系统上:
$ rebase -si | awk '{ print $3,$1}' |sort |head -n 5
0x0003ce2c0000 /usr/libexec/coreutils/libstdbuf.so
0x0003ce2d0000 /usr/lib/texinfo/XSParagraph.dll
0x0003ce2e0000 /usr/lib/texinfo/Parsetexi.dll
0x0003ce310000 /usr/lib/texinfo/MiscXS.dll
0x0003ce320000 /usr/lib/sasl2_3/cygscram-3.dll
$ rebase -si | awk '{ print $3,$1}' |sort -r |head -n 5
0x0003fffd0000 /usr/bin/cygEGL-1.dll
0x0003fffa0000 /usr/bin/cygEMF-1.dll
0x0003fff20000 /usr/bin/cygFLAC-8.dll
0x0003ffea0000 /usr/bin/cygGL-1.dll
0x0003ffe30000 /usr/bin/cygGLU-1.dll
因此,或者您的数据库已损坏并且重新设置基准未正确执行,或者BLODA正在干扰正确加载dll。
FileExistsError:[Errno 17] 文件存在:python3 中的“2021-07-31_1044”
如何解决FileExistsError:[Errno 17] 文件存在:python3 中的“2021-07-31_1044”?
#!/usr/bin/python3
"""Script to take backups."""
import os
import sys
import shutil
import datetime
class Backup:
def __init__(self,source,destination):
self.source = os.path.normpath(source)
self.destination = os.path.join(os.path.normpath(destination),os.path.basename(source))
if not os.path.isdir(self.destination):
self.destination = datetime.datetime.Now().strftime(''%Y-%m-%d_%H%M'')
print("Creating destination folder {} because it does not exist yet.".format(self.destination))
os.makedirs(self.destination)
def sync(self):
"""Synchronizes source to destination."""
for dir_path,dirnames,filenames in os.walk(self.source):
self.sync_directories(dir_path,dirnames)
self.sync_files(dir_path,filenames)
def _dest_path(self,dir_path,name):
return os.path.join(self.destination,os.path.relpath(dir_path,self.source),name)
def sync_directories(self,dirnames):
"""Create all directories in dirnames not already present in destination"""
for dir_name in dirnames:
dest_dir_name = self._dest_path(dir_path,dir_name)
if not os.path.exists(dest_dir_name):
print("mkdir",dest_dir_name)
os.mkdir(dest_dir_name)
def sync_files(self,filenames):
"""copy all files in filenames to destination
Skips already existing files with the same hash"""
for file_name in filenames:
source = os.path.join(dir_path,file_name)
destination = self._dest_path(dir_path,file_name)
if os.path.isfile(destination):
if self.compare(source,destination):
# print("skip",destination)
continue
print("copy",destination)
shutil.copy2(source,destination)
def main():
"""Main entry point for the script."""
source = "/home/desktop-cc-20/file"
destination = "/home/desktop-cc-20/Desktop/md_backup_{0}"
backup = Backup(source,destination)
backup.sync()
if __name__ == ''__main__'':
sys.exit(main())
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log
通过Flask / Python运行Selenium时收到以下错误
browser = webdriver.Firefox()[Wed Mar 07 03:02:27.719608 2018] [:error] [pid 21555] [client 108.162.250.6:36139] File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__[Wed Mar 07 03:02:27.719611 2018] [:error] [pid 21555] [client 108.162.250.6:36139] log_path=log_path)[Wed Mar 07 03:02:27.719614 2018] [:error] [pid 21555] [client 108.162.250.6:36139] File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/service.py", line 44, in __init__[Wed Mar 07 03:02:27.719617 2018] [:error] [pid 21555] [client 108.162.250.6:36139] log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None[Wed Mar 07 03:02:27.719620 2018] [:error] [pid 21555] [client 108.162.250.6:36139] IOError: [Errno 13] Permission denied: ''geckodriver.log''
该功能是
def get_index(api_key): if str(api_key)!=the_api_key: return 401 base_url = ''www.google.com'' browser = webdriver.Firefox() browser.get(base_url) html = browser.page_source return html
如果直接进入应用程序目录并运行脚本(python run.py
),则不会收到该错误。
基于此,通过Flask运行时,日志文件似乎不可写,但该文件应位于何处?
geckdriver
可执行文件安装在 /usr/local/bin/
答案1
小编典典这些错误为我们提供了一些有关发生了什么错误的提示,如下所示:
[Wed Mar 07 03:02:27.719608 2018] [:error] [pid 21555] [client 108.162.250.6:36139] File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__[Wed Mar 07 03:02:27.719611 2018] [:error] [pid 21555] [client 108.162.250.6:36139] log_path=log_path)
按照源代码中的 GeckoDriver 得到了两个默认参数发起executable_path
和log_path=log_path
如下:
if capabilities.get("marionette"): capabilities.pop("marionette") self.service = Service(executable_path, log_path=log_path) self.service.start()
您的程序在这里出错,因为与 key log_path* 对应的 Value log_path
(log_file
)是不可编辑的(附加的),最终失败了: __*
[Wed Mar 07 03:02:27.719617 2018] [:error] [pid 21555] [client 108.162.250.6:36139] log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None[Wed Mar 07 03:02:27.719620 2018] [:error] [pid 21555] [client 108.162.250.6:36139] IOError: [Errno 13] Permission denied: ''geckodriver.log''
根据源代码,默认情况下启动 GeckoDriver服务 ,如下所示:
class Service(service.Service):“”“管理GeckoDriver的启动和停止的对象。”“”
def __init__(self, executable_path, port=0, service_args=None, log_path="geckodriver.log", env=None): """Creates a new instance of the GeckoDriver remote service proxy. GeckoDriver provides a HTTP interface speaking the W3C WebDriver protocol to Marionette. :param log_path: Optional path for the GeckoDriver to log to. Defaults to _geckodriver.log_ in the current working directory. """ log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
这意味着如果您没有通过geckodriver.log
程序显式传递位置,则 GeckoDriver 倾向于在 当前工作目录中
自行创建文件,并且在缺少所需 权限的 情况下,它会出错,并显示以下消息: Permission denied:’geckodriver.log
‘
解
首要的一点是检查所使用的二进制文件之间的兼容性。
- 确保您使用的是 Selenium-Python Client v3.10.0 , GeckoDriver v0.19.1 和 _ Firefox Quantum v58.0.2_
一个解决方案是:
初始化 GeckoDriver 与所需的参数
executable_path
和log_path
与 有效的值(CHMOD 777geckodriver.log
),如下所示:def get_index(api_key):if str(api_key)!=the_api_key:return 401base_url = ''www.google.com''browser = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver", log_path="/path/to/geckodriver.log")browser.get(base_url)html = browser.page_sourcereturn html
如果您打算
geckodriver.log
在 Project Workspace中 创建,请确保所需的权限(chmod 777Project Workspace
)如下:def get_index(api_key):if str(api_key)!=the_api_key:return 401base_url = ''www.google.com''browser = webdriver.Firefox(executable_path=''/usr/local/bin/geckodriver'')browser.get(base_url)html = browser.page_sourcereturn html
IOError:[Errno 22]无效模式('r')或文件名:'c:\ Python27 test.txt'
如何解决IOError:[Errno 22]无效模式(''r'')或文件名:''c:\\\ Python27 \ test.txt''?
\t
是制表符。请使用原始字符串:
test_file=open(r''c:\Python27\test.txt'',''r'')
或将斜杠加倍:
test_file=open(''c:\\Python27\\test.txt'',''r'')
或改用正斜杠:
test_file=open(''c:/Python27/test.txt'',''r'')
解决方法
以下是什么问题:
test_file=open(''c:\\Python27\test.txt'',''r'')
关于IOError:[Errno 32]管道损坏:Python的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Cygwin上使用Python 3.7的Flask / Werkzeug:BlockingIOError:[Errno 11]资源暂时不可用、FileExistsError:[Errno 17] 文件存在:python3 中的“2021-07-31_1044”、IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log、IOError:[Errno 22]无效模式('r')或文件名:'c:\ Python27 test.txt'的相关知识,请在本站寻找。
本文标签: