0
在此先感谢。我有一个从表单发布数据创建的字典。我想将字典的内容打印到另一个文件。我不想用它输出到一个html页面。打印cgi fieldstorage对象到文件而不是html页面python
def cgiFieldStorageToDict(fieldStorage):
# Makes a dictionary from the http post data
params = {}
for key in fieldStorage.keys():
params[ key ] = fieldStorage[ key ].value
return params
my_dict = cgiFieldStorageToDict(cgi.FieldStorage())
s = open('dict_read.py','w')
z = str(my_dict)
s.write(z)
当我打开dict_read.py文件,我只看到一个空的字典:
{}
我要去哪里错了?
你确定实际上是在查询字符串(如果使用GET)或正文(如果使用POST)中将字段传递给CGI脚本。你如何提交HTTP请求? – mhawke
@mhawke是的,我正在使用发布数据。我想出了一个解决方案 –