外部访问时发现Python Bottle问题 [英] Python Bottle Issues when Accessed Externally

查看:191
本文介绍了外部访问时发现Python Bottle问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用python的瓶子模块来侦听服务器上的请求。我在本地完成了所有测试,现在已经到了部署时间,我无法在我的服务器上运行它。

 <$ 

@route('/ Request /< UniqueID>')#Build Temporary网页
def code> from bottle import route,get,post, login_form(UniqueID):
return'''< form method =POSTaction =/ SLR_Creation>
ID:< input name =UIDtype =textvalue ='''+ UniqueID +'''/>< br />
比例:< input name =Scaletype =textvalue =10000/>< br />
< input type =submitvalue =CLick here to create report/>
< / form>'''

@route('/< UniqueID>',method ='POST')#返回
def PHPH_Script(UniqueID):
#创建报告的大长脚本
return'''< p>报告已创建。点击此按钮即可访问它。< br />< / p>
< form action ='''+ WebLocation +'''。html>
< input type =submitvalue =CLick here to access report>
< / form>'''

#创建并运行页面
#run(host ='localhost',port = 8080)
run(host = '12 .34.255.89',port = 80)#这不是我的IP地址。

现在最后一行代码一直给我一个错误:错误:[ Errno 10049]请求的地址在上下文​​中无效。现在,如果我使用注释掉的行,它就像一个魅力。



我知道我的IP是正确的,并且端口是开放的,所以任何人都不知道我的问题在这里?

解决方案

问题:


  1. 端口80可能正在被其他任务使用,即使它崩溃了也是如此。


  2. 如果您使用say port 8080,您必须使用

    http://12.34.255.89:8080 / Request /...


  3. method ='POST' can遇到保护问题并且在某些情况下不可靠。

  4. 请参阅路线匹配,包括诸如 .html



So I am using the bottle module for python to listen for requests on my server. I've done all the testing locally and now that it has come time for deployment, I can't get it to run on my server.

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.

Now that last line of code is what keeps giving me an error of: error: [Errno 10049] The requested address is not valid in its context. Now if I use the commented out line, it works like a charm.

I know that my IP is correct and the port is open, so does anyone have any idea of what my issue is here?

解决方案

Maybe several issues:

  1. port 80 may be in use by another task, even if it crashed.

  2. If you use say port 8080 you have to use

    http://12.34.255.89:8080/Request/...

  3. method='POST' can run into protection issues and be unreliable in some cases.

  4. See that the route matches including things like .html

这篇关于外部访问时发现Python Bottle问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆