如何将表单数据发布到Microsoft Azure上的Python脚本?

时间:2016-12-26 00:43:37

标签: python azure cgi

我是Azure上的Python新手。我有三个文件位于我的wwwroot目录中,如下所示。我只是想从表单中POST一些字段并使用CGI模块检索它们。这在Apache服务器上运行良好,但在Azure上返回一个空的FieldStorage实例。

index.py

import cgi

def main(environ, start_response):

    markup_file = open("markup.txt")
    markup = markup_file.read()
    markup_file.close()

    fields = cgi.FieldStorage()

    start_response(b"200 OK", [(b"Content-Type", b"text/html")])
    yield (markup + str(fields)).encode("utf-8")

markup.txt

<html>
<body>
    <form action="" method="post">
        Message: <input type="text" name="message" />
        <input type="submit" value="Submit" />
    </form>
</body>
</html>

的web.config

<configuration>
    <appSettings>
        <add key="pythonpath" value="D:\home\site\wwwroot" />
        <add key="WSGI_HANDLER" value="index.main" />
    </appSettings>
</configuration>

是否有配置设置或其他一些我遗漏的明显事物?

1 个答案:

答案 0 :(得分:0)

根据您的代码,它似乎是一个WSGI Handle脚本,而不是CGI脚本。

因此,请按照WSGI Handle&amp;部分进行操作。官方文档Web.configConfiguring Python with Azure App Service Web Apps来重写您的代码并重新部署它。

如果您必须在Azure网站中使用CGI,MS MVP blog可能会对您有所帮助。