0

我正在尝试通过 HTTP 将参数传递给 python 脚本

例如http://www.domain.com/script.py?param=value

在某些示例中,我可以看到人们使用 cgi.FieldStorage() 函数来检索 GET 参数,但我无法使其工作

这是我的代码:

import cgi

print "Content-type: text/html\n"
arguments = cgi.FieldStorage()
print arguments

通过浏览器或通过命令行使用 wget 发出 http 请求,这是我为对象获得的输出arguments

FieldStorage(None, None, [])

似乎没有存储 GET 参数

我错过了什么?

4

1 回答 1

1

这样,它的工作原理!

import os, cgi

print "Content-Type: text/html\n"

query = os.environ.get('QUERY_STRING')
arguments = cgi.parse_qs(query) if query else {}
print arguments
于 2013-04-29T15:07:30.223 回答