python 3.x - deploying django in vercel function timeout - Stack Overflow

admin2025-05-02  1

i have a function called FetchAjaxs, which works fine in my local machine but not when i deploy

view.py

FetchAjaxs:
 #makes a api call to a different url which then returns a json to display in webpage

i am calling that function from a ajaxs in my html

index.html

$.ajax({
                    url: "{% url 'FetchAjaxs' %}", // Django URL for the view
                    type: "POST",
                    data: $(this).serialize(), // Serialize form data
                    headers: {
                        "X-CSRFToken": "{{ csrf_token }}" // Add CSRF token for security
                    },
                    dataType: 'json',

my url.py looks like this

path('fetch-ajax/', FetchAjaxs, name='FetchAjaxs'), 

and my vercel.json looks like this

{
    "builds": [{
        "src": "AppName/wsgi.py",
        "use": "@vercel/python",
        "config": { "maxLambdaSize": "15mb", "runtime": "python3.9", "maxDuration": 300}


    }

    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "AppName/wsgi.py"
        }
    ]
}

when i run this in my local machine it works but when i run it in vercel it doesnt i figured it has to do with time out

this is the error i get in my xhr

{"error": {"code": "504", "message": "An error occurred with your deployment"}}

i have increased the timeout in the settings in vercel

however i still get the same error, any help would be appreciated , also please note i am very new to vercel.

i have a function called FetchAjaxs, which works fine in my local machine but not when i deploy

view.py

FetchAjaxs:
 #makes a api call to a different url which then returns a json to display in webpage

i am calling that function from a ajaxs in my html

index.html

$.ajax({
                    url: "{% url 'FetchAjaxs' %}", // Django URL for the view
                    type: "POST",
                    data: $(this).serialize(), // Serialize form data
                    headers: {
                        "X-CSRFToken": "{{ csrf_token }}" // Add CSRF token for security
                    },
                    dataType: 'json',

my url.py looks like this

path('fetch-ajax/', FetchAjaxs, name='FetchAjaxs'), 

and my vercel.json looks like this

{
    "builds": [{
        "src": "AppName/wsgi.py",
        "use": "@vercel/python",
        "config": { "maxLambdaSize": "15mb", "runtime": "python3.9", "maxDuration": 300}


    }

    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "AppName/wsgi.py"
        }
    ]
}

when i run this in my local machine it works but when i run it in vercel it doesnt i figured it has to do with time out

this is the error i get in my xhr

{"error": {"code": "504", "message": "An error occurred with your deployment"}}

i have increased the timeout in the settings in vercel

however i still get the same error, any help would be appreciated , also please note i am very new to vercel.

Share Improve this question asked Jan 1 at 23:52 kunzkunz 1,0471 gold badge13 silver badges30 bronze badges 5
  • Quick one, Can you check the time taken to get a response from your API on your local? also are you using free vercel? – Idris Olokunola Commented Jan 5 at 11:34
  • it takes close to one and a half minute max two min – kunz Commented Jan 9 at 8:43
  • Do the runtime logs on Vercel not show anything? – Alexander Freyr Commented Jan 10 at 11:16
  • @kunz, try and optimize your function(make it async) so it can have a good time complexity and a shorter time response. if you dont mind, share your code or the github. – Idris Olokunola Commented Jan 10 at 19:36
  • @kunz, also use your inspect in your browser to check where the issue is probably coming from – Idris Olokunola Commented Jan 10 at 19:37
Add a comment  | 

1 Answer 1

Reset to default 1

https://vercel.com/guides/what-can-i-do-about-vercel-serverless-functions-timing-out

it might be because you are using a free tier qouting the docs

Maximum function durations

  • Maximum function durations
  • Hobby: 10s (default) - configurable up to 60s
  • Pro: 15s (default) - configurable up to 300s
  • Enterprise: 15s (default) - configurable up to 900s
转载请注明原文地址:http://anycun.com/QandA/1746139378a92121.html