Python Issue: Unsupported format, or corrupt file: Expected BOF record; found b'\n<html x'

Viewed 261

The below code is not working and showing an error. Can anyone suggest any solution? Note that The excel file format is xls. When I open the file manually, it shows a below message.

enter image description here

Regards, Ekram

import xlrd
file=xlrd.open_workbook("C:\\PzcharmProjects\\Track and Trace - Single Booking.xls")
sheet=file.sheet_by_index(0)
print(file.nrows)

Output:

---------------------------------------------------------------------------
XLRDError                                 Traceback (most recent call last)
<ipython-input-2-2279c402499e> in <module>
      1 import xlrd
----> 2 file=xlrd.open_workbook("C:\\PzcharmProjects\\Track and Trace - Single Booking.xls")
      3 sheet=file.sheet_by_index(0)
      4 print(file.nrows)

C:\Anaconda\lib\site-packages\xlrd\__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
    146 
    147     from . import book
--> 148     bk = book.open_workbook_xls(
    149         filename=filename,
    150         logfile=logfile,

C:\Anaconda\lib\site-packages\xlrd\book.py in open_workbook_xls(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
     90         t1 = perf_counter()
     91         bk.load_time_stage_1 = t1 - t0
---> 92         biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
     93         if not biff_version:
     94             raise XLRDError("Can't determine file's BIFF version")

C:\Anaconda\lib\site-packages\xlrd\book.py in getbof(self, rqd_stream)
   1276             bof_error('Expected BOF record; met end of file')
   1277         if opcode not in bofcodes:
-> 1278             bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
   1279         length = self.get2bytes()
   1280         if length == MY_EOF:

C:\Anaconda\lib\site-packages\xlrd\book.py in bof_error(msg)
   1270 
   1271         def bof_error(msg):
-> 1272             raise XLRDError('Unsupported format, or corrupt file: ' + msg)
   1273         savpos = self._position
   1274         opcode = self.get2bytes()

XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\n<html x'
0 Answers
Related