0

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)

2
  • Vercel cannot locate these two modules, causing the application to break whats the full error you are getting? Commented Mar 3, 2024 at 10:57
  • Please provide enough code so others can better understand or reproduce the problem. Commented Mar 3, 2024 at 12:04

1 Answer 1

0

I had the same issue with the handler and solved it using the tip mentioned in the link provided in the error, this one, by adding the handler.

from http.server import BaseHTTPRequestHandler
 
class handler(BaseHTTPRequestHandler):
 
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type','text/plain')
        self.end_headers()
        self.wfile.write('Hello, world!'.encode('utf-8'))
        return

I also had trouble finding the Flask module. This was resolved by setting the version in the requirements.txt file as shown here.

Flask==3.0.3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.