Python Tablib xlsx文件badZip文件问题

Python Tablib xlsx文件badZip文件问题,python,tablib,Python,Tablib,在windows 8中使用tablib库打开xlsx扩展文件时出错 python版本-2.7.14 错误如下: python suit_simple_sheet_product.py Traceback (most recent call last): File "suit_simple_sheet_product.py", line 19, in <module> data = tablib.Dataset().load(open(BASE_PATH).read())

在windows 8中使用tablib库打开xlsx扩展文件时出错

python版本-2.7.14

错误如下:

python suit_simple_sheet_product.py
Traceback (most recent call last):
  File "suit_simple_sheet_product.py", line 19, in <module>
    data = tablib.Dataset().load(open(BASE_PATH).read())
  File "C:\Python27\lib\site-packages\tablib\core.py", line 446, in load
    format = detect_format(in_stream)
  File "C:\Python27\lib\site-packages\tablib\core.py", line 1157, in detect_format
    if fmt.detect(stream):
  File "C:\Python27\lib\site-packages\tablib\formats\_xls.py", line 25, in detect
    xlrd.open_workbook(file_contents=stream)
  File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 120, in open_workbook
    zf = zipfile.ZipFile(timemachine.BYTES_IO(file_contents))
  File "C:\Python27\lib\zipfile.py", line 770, in __init__
    self._RealGetContents()
  File "C:\Python27\lib\zipfile.py", line 811, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file
python suit\u simple\u sheet\u product.py
回溯(最近一次呼叫最后一次):
文件“suit\u simple\u sheet\u product.py”,第19行,在
data=tablib.Dataset().load(打开(基本路径).read())
加载文件“C:\Python27\lib\site packages\tablib\core.py”,第446行
格式=检测\u格式(在\u流中)
文件“C:\Python27\lib\site packages\tablib\core.py”,第1157行,detect\U格式
如果fmt.检测(流):
文件“C:\Python27\lib\site packages\tablib\formats\\ uxls.py”,第25行,在detect中
xlrd.open_工作簿(文件内容=流)
文件“C:\Python27\lib\site packages\xlrd\\uuuuu init\uuuuuu.py”,第120行,在OpenU工作簿中
zf=zipfile.zipfile(timemachine.BYTES\u IO(文件内容))
文件“C:\Python27\lib\zipfile.py”,第770行,在_init中__
self.\u RealGetContents()
文件“C:\Python27\lib\zipfile.py”,第811行,在RealGetContents中
raise BadZipfile,“文件不是zip文件”
zipfile.BadZipfile:文件不是zip文件
路径位置如下所示=
基本路径='C:\Users\anju\Downloads\Automation\catalog-5090 fabric detail and price list.xlsx'

Excel
。xlsx
文件实际上是zip文件。为了使解压正确工作,必须以二进制模式打开文件,因此您需要使用以下方式打开文件:

import tablib

BASE_PATH = r'c:\my folder\my_test.xlsx'
data = tablib.Dataset().load(open(BASE_PATH, 'rb').read())

print data

在字符串之前添加
r
,以阻止Python尝试解释路径中的反斜杠字符。

您可以尝试
open(BASE_path,'rb')
以二进制模式打开xlsx文件。请提供一些完整的tablib示例。我已经尝试过你的技巧,但不知何故,我在使用它之后得到的数据并没有给出除工作表列名之外的所有行数据。你的xlsx文件可能使用了底层
xlrd
库不支持的功能。您可以使用类似的方法将文件上载到,并将URL粘贴到此处。