问题原因

在使用tarfile模块解压一份Linux服务器上的打包文件时, 出现了错误提示: IOError: [Errno 22] invalid mode ('wb') or filename.

经过检查, 发现是因为打包文件中有文件名存在':'符号, 而window下的文件名是不能有':'符号的因而报错.

解决办法

通过搜索, 找到了种解决办法, 可以将解压时含':'的地方转换成'_'等正常的符号

extract = tarfile.open(file)
for f in extract:
# add other unsavory characters in the brackets
f.name = re.sub(r'[:]', '_', f.name)
extract.extractall(path=new_path)
extract.close()

来源

http://stackoverflow.com/questions/30287036/python-tarfile-extraction-error-ioerror-errno-22-invalid-mode-wb-or-file

Python tarfile模块解压报错 invalid mode ('wb') or filename的更多相关文章

  1. MongoDB解压报错gzip: stdin: not in gzip format的解决方法

    MongoDB解压报错gzip: stdin: not in gzip format的解决方法 在安装MongoDB时出现如下报错: [root@vm172--- mongodb]# tar -zxv ...

  2. linux下 python源码包解压报错

    执行下面的命令 tar -zvxf Python.3.6.5.tgz 报错 gzip: stdin: not in gzip format tar: Child returned status 1 t ...

  3. memcached解压报错gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now的解决方法

    最近在部署环境,在安装memcached的过程中解压时, 解压命令:tar -zvxf memcached-1.4.34.tar.gz 遇到了一个问题, gzip: stdin: not in gzi ...

  4. 解压报错gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now的解决方法

    在部署tomcat的环境搞JDK的时候出现这个问题.分享一下. 解压命令:tar -zvxf memcached-1.4.34.tar.gz 遇到了一个问题, gzip: stdin: not in ...

  5. python安装模块的时候报错error: command 'gcc' failed with exit status 1

    [情况] 在写Python代码的时候,需要用到psutil模块,需要安装. 但是在安装时,报错:error: command 'gcc' failed with exit status 1 [解决步骤 ...

  6. linux下unzip解压报错“symlink error: File name too long”怎么办?提供解决方案。

    点击上方↑↑↑蓝字[协议分析与还原]关注我们 " 分享unzip工具的一个bug." 最近在研究菠菜站,中间用到了Spidermonkey,碰到一些小波折,在这里分享出来,以便大家 ...

  7. Unzip 解压报错

      $ jar xvf pcre-8.10.zip   如果出现 jar:Command not found 要用yum下载 $ yum -y install java-1.6.0-openjdk-d ...

  8. Python压缩及解压文件

    Zip压缩 #-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import zipfile #加载模块 # 压缩 z = zipf ...

  9. python安装包的时候报错

    python安装包的时候报错 今天兴致勃勃的安装了一个paramiko包,过程很顺利,但是到结尾的时候报错,这就让人不爽了. 所以呢,需要安装一个名为python-dev的软件包. 该软件包包括头文件 ...

随机推荐

  1. javascript深入浅出

    第一章 数据类型 1,六种数据类型:原始类型(number,string,boolean,null,undefined) + object对象(Function Array Date) 2,隐式转换: ...

  2. Win7 64位安装VS2013无法连接远程数据库

    win7 64位安装vs2013后连接远程数据库出现下面的问题:A first chance exception of type 'System.AccessViolationException' o ...

  3. Art-Template模板引擎(原生写法与简洁写法)

    模板引擎:把js数据转换成html需要的页面,这就是模板引擎需要做的事     • native原生语法     1. 准备数据     2. 把数据转化成html格式的字符串 使用模板引擎 artT ...

  4. XAMPP apache443端口被占用

    点击netstat,可以看到443端口被vmvare占用,那只能改端口了, config,选择Apache(http-ssl.conf)文件,找到443端口,改成其他不被占用的端口,就可以了.

  5. Android Fragment解析(下)

    今天被人问到了什么是Fragment,真是一头雾水,虽然以前也用到过,但不知道它是叫这个名字,狂补一下. 以下内容来自互联网,原文链接:http://blog.csdn.net/lmj62356579 ...

  6. DNS污染——domain name的解析被劫持了返回无效的ip

    看下dns污染: bash-3.2$ dig twitter.com +trace ; <<>> DiG 9.10.6 <<>> twitter.com ...

  7. oracle 修改字符集 修改为ZHS16GBK

    oracle数据库的字符集更改 A.oracle server 端 字符集查询 select userenv('language') from dual 其中NLS_CHARACTERSET 为ser ...

  8. TStringHelper.Split

    作为对泛型的支持,TStringHelper.Split方法理所应当地出现了. 示例代码1: var  iText: string;  iAStr: TArray<string>;  I: ...

  9. LeetCode OJ:Regular Expression Matching(正则表达式匹配)

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  10. win10 downloader.exe 修复方法

    由于系统更新是和系统密切相关的,在日常使用中某些系统文件如果出现损坏,同样会导致系统更新无法成功安装.如果在使用Windows 10时可以成功下载更新,但是安装的时候出错,此时就需要对系统文件进行检查 ...