【发布时间】:2013-10-28 06:55:54
【问题描述】:
我不确定为什么在向表单提交任何查询时,在 Google AppEngine 上托管此简单代码会返回服务器错误。问题似乎出在 html = urllib2.urlopen("http://google.com/search?q=" + q).read() 行上,因为没有它,代码也能正常工作。
import webapp2
import urllib2
form="""
<form action="/process">
<input name="q">
<input type="submit">
</form>
"""
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
class ProcessHandler(webapp2.RequestHandler):
def get(self):
q = self.request.get("q")
html = urllib2.urlopen("http://google.com/search?q=" + q).read()
self.response.out.write(html)
app = webapp2.WSGIApplication([('/', MainHandler),
('/process', ProcessHandler)],
debug=True)
这是返回的错误:
Error: Server Error
The server encountered an error and could not complete your request.
If the problem persists, please report your problem and mention this error message and the query that caused it.
【问题讨论】:
标签: python html google-app-engine python-2.7 urllib2