【发布时间】:2014-07-14 18:33:27
【问题描述】:
我使用 Google 应用引擎编写了一个简单的 WSGI 服务器。这是它的代码:
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('''
<html><head><title>BLAH</title></head>
<body>
<form type = "input" action = "/post" method = post>
<input type = text name = "name">
<input type = submit value = "Submit">
</form>
<hr>
</body>
</html>
''')
class EntrySubmission(webapp2.RequestHandler):
def post(self):
n = self.request.get('name')
self.response.write('''<html><head><title>%s</title></head>
<body>
<h1>Welcome %s</h1>
<br>How are you today?
<br><a href = "/">Back</a>
<hr>
</body>
</html>''' % (n,n))
app = webapp2.WSGIApplication([
('/', MainHandler),
('/post',EntrySubmission),
], debug=True)
当我手动输入值时,服务器工作正常。但是当我使用 python 输入值时,它会给出 405 响应。可能是什么问题呢? python输入代码:
import requests,json
url = 'http://localhost:9080/'
header = {'content-type' : 'application/json'}
d = {'name' : 'Foo'}
r = requests.post(url,data = json.dumps(d),headers = header)
如果我使用 urrlib2 而不是请求,也会出现同样的问题。我什至尝试在不发送标头的情况下使用它。
【问题讨论】:
标签: python html google-app-engine