vercel / vercel/examples

Python Example Issue

Open
#535 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.2k
Forks
1.8k
Avg merge
3d 12h
Merged PRs (30d)
6

Description

Hello,

I've been trying to use the python api example code and am experiencing some weird behavior. When I use the provided deploy button and deploy it as a new project to my account everything works as expected. When I copy the code into a project that I have already created (with other development branches and domains attached) and run vercel to deploy it I get the following error:

Error: No Next.js version could be detected in your project. Make sure `"next"` is installed in "dependencies" or "devDependencies"
Error: Check your logs at ...

From what I found, that is because I need to add the "builds": [{ "src": "./api/index.py", "use": "@vercel/python" }] line to my vercel.json file. When I do that, it allows the vercel build command to complete properly. Once that completes, I go to the preview link that the vercel command spits out but I get another error:

This Serverless Function has crashed.

Your connection is working correctly.

Vercel is working correctly.

500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED
ID: ...

I followed the logs link to see what errors came up and it seems like the error is not always the same. Sometimes it has this error:

[GET] /api
02:42:37:36
[ERROR] TypeError: expected string or bytes-like object
Traceback (most recent call last):
  File "/var/task/vc__handler__python.py", line 63, in vc_handler
    conn.request(method, path, headers=headers, body=request_body)
  File "/var/lang/lib/python3.9/http/client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/var/lang/lib/python3.9/http/client.py", line 1326, in _send_request
    self.putheader(hdr, value)
  File "/var/lang/lib/python3.9/http/client.py", line 1262, in putheader
    if _is_illegal_header_value(values[i]):

And sometimes it has this error:

[OPTIONS] /api
02:42:37:64
127.0.0.1 - - [30/Jan/2023 07:42:37] code 501, message Unsupported method ('OPTIONS')
127.0.0.1 - - [30/Jan/2023 07:42:37] "OPTIONS /api HTTP/1.1" 501 -

Any idea where I might be going wrong?

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the deploy-button project with the existing project’s vercel.json and api/index.py, then reproduce the deployment with the vercel command and inspect the function logs. Done means the Python example deploys in an existing project without the Next.js detection or FUNCTION_INVOCATION_FAILED errors, including requests that trigger OPTIONS.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, python
Domain
api, backend, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.