我试图通过HTTP传递一个参数给python脚本
。http://www.domain.com/script.py?param=value
在一些例子中,我可以看到人们使用cgi.FieldStorage()函数来检索GET参数,但我不能使它工作
这是我的代码:
import cgi
print "Content-type: text/htmln"
arguments = cgi.FieldStorage()
print arguments
通过浏览器或通过wget命令行发出http请求,这是我得到的对象arguments
的输出:
FieldStorage(None, None, [])
似乎没有存储GET参数
我错过了什么?
这样就可以了!
import os, cgi
print "Content-Type: text/htmln"
query = os.environ.get('QUERY_STRING')
arguments = cgi.parse_qs(query) if query else {}
print arguments