Forums

"Something went wrong" message- you must specify an engine manually.

Last night my apps were working fine, this morning I am getting this error:

Looks like to do with pandas and my excel file

ValueError: Excel file format cannot be determined, you must specify an engine manually. 2022-09-09 13:56:55,276: Error running WSGI application 2022-09-09 13:56:55,277: ValueError: Excel file format cannot be determined, you must specify an engine manually. 2022-09-09 13:56:55,277: File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2069, in call 2022-09-09 13:56:55,277: return self.wsgi_app(environ, start_response)

I didn't change anything to my app since last night. I am getting the same error on another app that I haven't played with in a while too.

Did PythonAnywhere just install a new pandas version to all the servers or something maybe?

Any ideas what might have happened, Im not sure how to tackle this error :(

Based on our email exchange, this was a user uploading a file that was not an Excel file.

I've got the same problem, but no solution...

Can you please provide more details?

The error message looks like this:

File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(req.view_args) File "/home/christofferrydestahl/mysite/webapp.py", line 63, in index df = pd.read_excel(file_path) File "/usr/local/lib/python3.10/site-packages/pandas/util/_decorators.py", line 311, in wrapper return func(*args, kwargs) File "/usr/local/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 364, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) File "/usr/local/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 1195, in init raise ValueError( ValueError: Excel file format cannot be determined, you must specify an engine manually. <br> <br> <br> In my code I've specified the like this:

        # Read Excel-filen
        df = pd.read_excel(file_path, engine='openpyxl')
        names = df['Name'].tolist()
        results = []

This looks like your problem:

Excel file format cannot be determined, you must specify an engine manually

so it looks like you need to tell Pandas which engine to use in order to load the Excel file. The docs provide a list of engines that can be used. You should also check that the file that you're trying to load is actually an Excel file.

I thought I already did specify the engine here:

df = pd.read_excel(file_path, engine='openpyxl')

The file is an .xlsx-file.

The strange thing is that the app is working locally.

Maybe you did not reload your web app after making that change. From the trackback it looks like the line executed was df = pd.read_excel(file_path)

Well, it strange. This is the code from line 63:

63: uploaded_file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) file.save(file_path)

        # Read the Excel-filen
        try:
            df = pd.read_excel(uploaded_file_path, engine='openpyxl')
            names = df['Name'].tolist()
            results = []
        except:
            print("Error reading the god damn Excel file")

I've tried to delete the .cache directory but it still gives me the same error even though I reloaded the app.

Look in the most recent tracebacl (lines in the error log have timestamps) and check whether the traceback is still missing the engine argument. If it is, then make sure that you are editing the correct file (the path to the file is also in the traceback)

Sorry, there was a path issue. But now I get this error that I've been trying to solve but keeps getting stuck.

In the error logs: "zipfile.BadZipFile: File is not a zip file"

But I'm uploading a .xlsx file.

In the browser I get another message: Error: Uploaded file is corrupted or not a valid Excel file.

I believe a .xlsx file is a zip file that contains other files with the content of the sheets, so I'd guess that your .xlsx is corrupt in some way or maybe it's not really a .xlsx but just has that extension.