简体   繁体   English

如何使用cgi接受带有python脚本的发布请求?

[英]How do I accept post requests with a python script using cgi?

I want to submit text to an HTML form and send it to a Python script. 我想将文本提交到HTML表单并将其发送到Python脚本。 When I press the submit button it takes me to an error page that says: 当我按下提交按钮时,它会转到一个错误页面,上面写着:

Error code: 501 Message: Unsupported method ('POST'). 错误代码:501消息:不支持的方法('POST')。 Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation. 错误代码说明:HTTPStatus.NOT_IMPLEMENTED - 服务器不支持此操作。

I'm not exactly sure what the issue is. 我不确定问题是什么。 I've googled the error message and have looked through different documentation and watched some videos but they are seem to gloss over how to set up the server correctly. 我已经搜索了错误消息并查看了不同的文档并观看了一些视频,但它们似乎掩盖了如何正确设置服务器。

I'm running Python 3.7. 我正在运行Python 3.7。

<form action="www/cgi-bin/hello.py" method="post">
First Name: 
<input type="text" name="first_name" placeholder="e.g. Barack" required="required"/>

Last Name: 
<input type="text" name="last_name" placeholder="e.g. Obama" required="required"/>

<input type="submit" name="submitprompt" value="Submit"/>
</form>
#!/usr/bin/python

import cgi, cgitb

first_name = form.getvalue('first_name')
last_name  = form.getvalue('last_name')
print("Content-type:text/html")
print("")
print("")
print("Hello - Second CGI Program")
print("")
print("")
print("   Hello %s %s" % (first_name, last_name))
print("")
print("")

I'm expecting to be taken a page that has the text: Hello first_name last_name . 我希望得到一个包含文本的页面: Hello first_name last_name Instead, I receive the aforementioned error. 相反,我收到上述错误。

使用命令“python3 -m http.server --cgi 8000”并从那里配置解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Python请求发布到CGI脚本 - Using Python requests to POST to a cgi script 如何在Apache上使用基本的Python CGI脚本处理POST请求? - How can one process POST requests with a basic Python CGI script on Apache? 如何在不使用 cgi.FieldStorage 的情况下从帖子中获取 args 或获取 Python - How do I get the args from a post or get with Python without using cgi.FieldStorage 如何使用JavaScript从CGI脚本调用python函数? - How do I call a python function from a cgi script with javascript? 如何获得在 Apache2 中运行的 Python cgi 脚本 - How do I get a Python cgi script running in Apache2 在我的Python CGI脚本中,如何将用户通过表单输入的数据通过POST请求上传到磁盘上的文件保存到磁盘上? - In my Python CGI script, how do I save to disk a file uploaded via POST request of data entered by the user in a form? 如何配置包含脚本的 Python post Requests 命令 - How do configure a Python post Requests command that includes a script 在Python3 CGI脚本中,如何在POST中读取原始表单数据? - In a Python3 CGI script, how can I read the raw form data in a POST? 如何让 Google Cloud Functions 接受大于 10KB 的 POST 请求? - How do I make Google Cloud Functions accept POST requests larger than 10KB? 如何从 python CGI 脚本中的 POST 数据中获取文件? - How to get a file from POST data in python CGI script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM