Error in import module Flask application deploy in vercel using vercel.json

20 Views Asked by At

I'm encountering an issue while attempting to deploy my Flask application to Vercel using a vercel.json file. My application consists of a main.py file where the application is initialized. This file then calls a module named ScraperAPI, which is responsible for creating my Flask app and running it. Additionally, another module named ProcessSearcher is called, which performs web scraping on a site based on a name field passed through a POST request.

However, Vercel cannot locate these two modules, causing the application to break. I have already attempted to consolidate everything into a single file for deployment, but encountered errors related to the handler and Flask.app being inaccessible.

{
    "rewrites": [
        {
            "source": "/(.*)",
            "destination": "/api/main.py"
        }
    ]
}

The remaining code is available in the repository, as it would be cumbersome to include it all here.

https://github.com/pedroblome/web_scrapping

Anyone who has experience configuring Vercel for a simple Flask application with additional `.py` files would greatly assist me. Their expertise and guidance would be invaluable in resolving this issue efficiently.

I have created a vercel.json file specifying that my application starts with ./api/main.py, and all routes should redirect to it.

Based on the tutorials I've watched, it wasn't necessary to explicitly list all the .py files used in the application within the vercel.json file.

the code error:

Installing required dependencies...

Built @vercel/python:main.py [20s] Missing variable handler or app in file "main.py". See the docs: https://vercel.com/docs/functions/serverless-functions/runtimes/python LambdaError: RequestId: 23919ddb-5802-4485-8abc-73129e3018fa Process exited before completing request at Lambda. (/usr/local/lib/node_modules/vercel/node_modules/@vercel/fun/dist/src/index.js:110:27) at Generator.next () at fulfilled (/usr/local/lib/node_modules/vercel/node_modules/@vercel/fun/dist/src/index.js:24:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Missing variable handler or app in file "main.py". See the docs: https://vercel.com/docs/functions/serverless-functions/runtimes/python LambdaError: RequestId: 45e949fe-a712-4662-9ddd-cc37e4786099 Process exited before completing request at Lambda. (/usr/local/lib/node_modules/vercel/node_modules/@vercel/fun/dist/src/index.js:110:27) at Generator.next () at fulfilled (/usr/local/lib/node_modules/vercel/node_modules/@vercel/fun/dist/src/index.js:24:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

0

There are 0 best solutions below