我正在尝试使用Python 3.4.3和Bottle 0.12.8来使用cgi运行简单的Web服务。我从Linux系统运行以下脚本。我能够在没有CGI的情况下运行相同的服务。
======================================
import bottle
from bottle import route, run, request, response
host = 'XXXX'
port = '8080'
debug = 'False'
@route('/hello/', method=['OPTIONS','GET'])
def hello():
return("Success")
bottle.run(host=host, port=port,debug=debug,server='cgi')
#bottle.run(host=host, port=port,debug=debug)
======================================
当我使用CGI-
运行服务时,我得到以下错误Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/bottle.py", line 858, in _handle
route, args = self.router.match(environ)
File "/usr/local/lib/python3.4/site-packages/bottle.py", line 413, in match
verb = environ['REQUEST_METHOD'].upper()
KeyError: 'REQUEST_METHOD'
<h1>Critical error while processing request: </h1><h2>Error:</h2>
<pre>
KeyError('REQUEST_METHOD',)
</pre>
<h2>Traceback:</h2>
<pre>
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/bottle.py", line 957, in wsgi
or environ['REQUEST_METHOD'] == 'HEAD':
KeyError: 'REQUEST_METHOD'
</pre>
Status: 500 INTERNAL SERVER ERROR
Content-Type: text/html; charset=UTF-8
Content-Length: 374
<h1>Critical error while processing request: </h1><h2>Error:</h2>
<pre>
KeyError('REQUEST_METHOD',)
</pre>
<h2>Traceback:</h2>
<pre>
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/bottle.py", line 957, in wsgi
or environ['REQUEST_METHOD'] == 'HEAD':
KeyError: 'REQUEST_METHOD'
</pre>
Any pointers would help. Thanks
答案 0 :(得分:0)
您收到此错误,因为basic CGI HTTP server in Python仅支持GET,HEAD和POST命令。 CGI服务器在尝试验证OPTIONS命令时抛出KeyError。如果要在服务器代码中使用OPTIONS方法,则需要自己实现或切换到其他服务器。