外部访问时的Python Bottle问题
我正在使用Python的Bottle模块来监听我服务器上的请求。我在本地测试了一切都没问题,但现在到了部署的时候,我却无法在服务器上运行它。
from bottle import route, get, post, request, Bottle, run, template
@route('/Request/<UniqueID>') #Build Temporary Webpage
def login_form(UniqueID):
return '''<form method="POST" action="/SLR_Creation">
ID: <input name="UID" type="text" value="''' +UniqueID+ '''" /><br />
Scale: <input name="Scale" type="text" value="10000"/><br />
<input type="submit" value="CLick here to create report"/>
</form>'''
@route('/<UniqueID>', method='POST') # Return
def PHPH_Script(UniqueID):
# Big long script to create a report
return '''<p>The report has been created. Click this button to access it.<br /></p>
<form action="''' + WebLocation +'''.html">
<input type="submit" value="CLick here to access report">
</form>'''
# Create and Run Page
#run(host='localhost', port=8080)
run(host='12.34.255.89', port=80) # This is not my actually IP Address.
最后一行代码总是给我报错:错误:[Errno 10049] 请求的地址在当前上下文中无效。 如果我使用注释掉的那行代码,就能正常工作。
我知道我的IP是正确的,端口也已经打开,那么有没有人知道我这里的问题是什么呢?
1 个回答
1
可能有几个问题:
端口80可能被其他任务占用,即使那个任务已经崩溃了。
如果你使用的是8080端口,那么你需要这样访问:
http://12.34.255.89:8080/Request/...
method='POST'
在某些情况下可能会遇到保护问题,而且不太可靠。确保路径匹配,包括像
.html
这样的东西。