librelist archives

« back to archive

Config problems

Config problems

From:
Xavier
Date:
2015-07-13 @ 20:46
Hi,

I'm not be able to load configuration:

from flask import Flask
app = Flask(__name__)

app.config['port'] = 8000

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()



This app serves itself in port 5000 not in 8000. Why? Perhaps a simple 
question but in the manual I could not get the answer.
Any help?

Thanks in advance,
Xavier

Re: [flask] Config problems

From:
Mike Nickey
Date:
2015-07-13 @ 20:57
Just a precursor glance and it seems like this can be done in a different
way. You can specify the port like so.

if __name__ == '__main__':
      app.run(host='0.0.0.0', port=80)

The link source can be found here.
http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80

If this doesn't work or other have a different idea please let me know. I'm
always ready to learn more.

On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com> wrote:

> Hi,
>
> I'm not be able to load configuration:
>
> from flask import Flask
> app = Flask(__name__)
>
> app.config['port'] = 8000
>
> @app.route("/")
> def hello():
>     return "Hello World!"
>
> if __name__ == "__main__":
>     app.run()
>
>
>
> This app serves itself in port 5000 not in 8000. Why? Perhaps a simple
> question but in the manual I could not get the answer.
> Any help?
>
> Thanks in advance,
> Xavier
>



-- 
~MEN

Re: [flask] Config problems

From:
Xavier
Date:
2015-07-13 @ 21:08
Yeah I know I can pass 'port' option directly to app.run. But I want to do
it (and also pass other things) thought config.

Thanks for all,


On Mon, 13 Jul 2015 13:57:26 -0700
Mike Nickey <mnickey@gmail.com> ha escrit:

> Just a precursor glance and it seems like this can be done in a different
> way. You can specify the port like so.
> 
> if __name__ == '__main__':
>       app.run(host='0.0.0.0', port=80)
> 
> The link source can be found here.
> http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80
> 
> If this doesn't work or other have a different idea please let me know. I'm
> always ready to learn more.
> 
> On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com> wrote:
> 
> > Hi,
> >
> > I'm not be able to load configuration:
> >
> > from flask import Flask
> > app = Flask(__name__)
> >
> > app.config['port'] = 8000
> >
> > @app.route("/")
> > def hello():
> >     return "Hello World!"
> >
> > if __name__ == "__main__":
> >     app.run()
> >
> >
> >
> > This app serves itself in port 5000 not in 8000. Why? Perhaps a simple
> > question but in the manual I could not get the answer.
> > Any help?
> >
> > Thanks in advance,
> > Xavier
> >
> 
> 
> 
> -- 
> ~MEN

Re: [flask] Config problems

From:
gideon namane
Date:
2015-07-13 @ 21:17
Hello I'm new to this too but how about you do....
app.config.from_object(_name_)
app.config['port']=8000
On Jul 13, 2015 11:13 PM, "Xavier" <somenxavier@gmail.com> wrote:

> Yeah I know I can pass 'port' option directly to app.run. But I want to do
> it (and also pass other things) thought config.
>
> Thanks for all,
>
>
> On Mon, 13 Jul 2015 13:57:26 -0700
> Mike Nickey <mnickey@gmail.com> ha escrit:
>
> > Just a precursor glance and it seems like this can be done in a different
> > way. You can specify the port like so.
> >
> > if __name__ == '__main__':
> >       app.run(host='0.0.0.0', port=80)
> >
> > The link source can be found here.
> >
> http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80
> >
> > If this doesn't work or other have a different idea please let me know.
> I'm
> > always ready to learn more.
> >
> > On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > I'm not be able to load configuration:
> > >
> > > from flask import Flask
> > > app = Flask(__name__)
> > >
> > > app.config['port'] = 8000
> > >
> > > @app.route("/")
> > > def hello():
> > >     return "Hello World!"
> > >
> > > if __name__ == "__main__":
> > >     app.run()
> > >
> > >
> > >
> > > This app serves itself in port 5000 not in 8000. Why? Perhaps a simple
> > > question but in the manual I could not get the answer.
> > > Any help?
> > >
> > > Thanks in advance,
> > > Xavier
> > >
> >
> >
> >
> > --
> > ~MEN
>

Re: [flask] Config problems

From:
Minglangjun Li
Date:
2015-07-14 @ 00:50
There isn't a 'port' option, what you need is 'SERVER_NAME'.
app.config['SERVER_NAME'] = '127.0.0.1:8000'

Ref: http://flask.pocoo.org/docs/0.10/api/#application-object

Best,
Minglangjun Li

On 7/13/15, gideon namane <kpedronams@gmail.com> wrote:
> Hello I'm new to this too but how about you do....
> app.config.from_object(_name_)
> app.config['port']=8000
> On Jul 13, 2015 11:13 PM, "Xavier" <somenxavier@gmail.com> wrote:
>
>> Yeah I know I can pass 'port' option directly to app.run. But I want to
>> do
>> it (and also pass other things) thought config.
>>
>> Thanks for all,
>>
>>
>> On Mon, 13 Jul 2015 13:57:26 -0700
>> Mike Nickey <mnickey@gmail.com> ha escrit:
>>
>> > Just a precursor glance and it seems like this can be done in a
>> > different
>> > way. You can specify the port like so.
>> >
>> > if __name__ == '__main__':
>> >       app.run(host='0.0.0.0', port=80)
>> >
>> > The link source can be found here.
>> >
>> 
http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80
>> >
>> > If this doesn't work or other have a different idea please let me know.
>> I'm
>> > always ready to learn more.
>> >
>> > On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com> wrote:
>> >
>> > > Hi,
>> > >
>> > > I'm not be able to load configuration:
>> > >
>> > > from flask import Flask
>> > > app = Flask(__name__)
>> > >
>> > > app.config['port'] = 8000
>> > >
>> > > @app.route("/")
>> > > def hello():
>> > >     return "Hello World!"
>> > >
>> > > if __name__ == "__main__":
>> > >     app.run()
>> > >
>> > >
>> > >
>> > > This app serves itself in port 5000 not in 8000. Why? Perhaps a
>> > > simple
>> > > question but in the manual I could not get the answer.
>> > > Any help?
>> > >
>> > > Thanks in advance,
>> > > Xavier
>> > >
>> >
>> >
>> >
>> > --
>> > ~MEN
>>
>

Re: [flask] Config problems

From:
Xavier
Date:
2015-07-14 @ 09:19
Yes. It's true. It's a little bit incoherence here: in config 
'SERVER_NAME' and in app params 'port' !!!

On the other hand, is there any trick about these parameters:
DEBUG = True
SECRET_KEY = 'thisissomeplainpassword!'
RDB_HOST = 'localhost'
RDB_PORT = 28015
RDB_NAME = 'gargamelladb'
RDB_TB_USERS = 'users'

?

Thanks,


On Tue, 14 Jul 2015 00:50:39 +0000
Minglangjun Li <liminglangjun@gmail.com> ha escrit:

> There isn't a 'port' option, what you need is 'SERVER_NAME'.
> app.config['SERVER_NAME'] = '127.0.0.1:8000'
> 
> Ref: http://flask.pocoo.org/docs/0.10/api/#application-object
> 
> Best,
> Minglangjun Li
> 
> On 7/13/15, gideon namane <kpedronams@gmail.com> wrote:
> > Hello I'm new to this too but how about you do....
> > app.config.from_object(_name_)
> > app.config['port']=8000
> > On Jul 13, 2015 11:13 PM, "Xavier" <somenxavier@gmail.com> wrote:
> >
> >> Yeah I know I can pass 'port' option directly to app.run. But I want to
> >> do
> >> it (and also pass other things) thought config.
> >>
> >> Thanks for all,
> >>
> >>
> >> On Mon, 13 Jul 2015 13:57:26 -0700
> >> Mike Nickey <mnickey@gmail.com> ha escrit:
> >>
> >> > Just a precursor glance and it seems like this can be done in a
> >> > different
> >> > way. You can specify the port like so.
> >> >
> >> > if __name__ == '__main__':
> >> >       app.run(host='0.0.0.0', port=80)
> >> >
> >> > The link source can be found here.
> >> >
> >> 
http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80
> >> >
> >> > If this doesn't work or other have a different idea please let me know.
> >> I'm
> >> > always ready to learn more.
> >> >
> >> > On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com> wrote:
> >> >
> >> > > Hi,
> >> > >
> >> > > I'm not be able to load configuration:
> >> > >
> >> > > from flask import Flask
> >> > > app = Flask(__name__)
> >> > >
> >> > > app.config['port'] = 8000
> >> > >
> >> > > @app.route("/")
> >> > > def hello():
> >> > >     return "Hello World!"
> >> > >
> >> > > if __name__ == "__main__":
> >> > >     app.run()
> >> > >
> >> > >
> >> > >
> >> > > This app serves itself in port 5000 not in 8000. Why? Perhaps a
> >> > > simple
> >> > > question but in the manual I could not get the answer.
> >> > > Any help?
> >> > >
> >> > > Thanks in advance,
> >> > > Xavier
> >> > >
> >> >
> >> >
> >> >
> >> > --
> >> > ~MEN
> >>
> >

Re: [flask] Config problems

From:
Xavier
Date:
2015-07-14 @ 09:34
But 

app.config['SERVER_NAME'] = '0.0.0.0:8000'

is ignored (127.0.0.1:8000 is used)

Why?

On Tue, 14 Jul 2015 00:50:39 +0000
Minglangjun Li <liminglangjun@gmail.com> ha escrit:

> There isn't a 'port' option, what you need is 'SERVER_NAME'.
> app.config['SERVER_NAME'] = '127.0.0.1:8000'
> 
> Ref: http://flask.pocoo.org/docs/0.10/api/#application-object
> 
> Best,
> Minglangjun Li
> 
> On 7/13/15, gideon namane <kpedronams@gmail.com> wrote:
> > Hello I'm new to this too but how about you do....
> > app.config.from_object(_name_)
> > app.config['port']=8000
> > On Jul 13, 2015 11:13 PM, "Xavier" <somenxavier@gmail.com> wrote:
> >
> >> Yeah I know I can pass 'port' option directly to app.run. But I want to
> >> do
> >> it (and also pass other things) thought config.
> >>
> >> Thanks for all,
> >>
> >>
> >> On Mon, 13 Jul 2015 13:57:26 -0700
> >> Mike Nickey <mnickey@gmail.com> ha escrit:
> >>
> >> > Just a precursor glance and it seems like this can be done in a
> >> > different
> >> > way. You can specify the port like so.
> >> >
> >> > if __name__ == '__main__':
> >> >       app.run(host='0.0.0.0', port=80)
> >> >
> >> > The link source can be found here.
> >> >
> >> 
http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80
> >> >
> >> > If this doesn't work or other have a different idea please let me know.
> >> I'm
> >> > always ready to learn more.
> >> >
> >> > On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com> wrote:
> >> >
> >> > > Hi,
> >> > >
> >> > > I'm not be able to load configuration:
> >> > >
> >> > > from flask import Flask
> >> > > app = Flask(__name__)
> >> > >
> >> > > app.config['port'] = 8000
> >> > >
> >> > > @app.route("/")
> >> > > def hello():
> >> > >     return "Hello World!"
> >> > >
> >> > > if __name__ == "__main__":
> >> > >     app.run()
> >> > >
> >> > >
> >> > >
> >> > > This app serves itself in port 5000 not in 8000. Why? Perhaps a
> >> > > simple
> >> > > question but in the manual I could not get the answer.
> >> > > Any help?
> >> > >
> >> > > Thanks in advance,
> >> > > Xavier
> >> > >
> >> >
> >> >
> >> >
> >> > --
> >> > ~MEN
> >>
> >

Re: [flask] Config problems

From:
Minglangjun Li
Date:
2015-07-14 @ 11:49
Found the answer in the source code, *flask/app.py*

    if host is None:
        host = '127.0.0.1'
    if port is None:
        server_name = self.config['SERVER_NAME']
        if server_name and ':' in server_name:
             port = int(server_name.rsplit(':', 1)[1])
        else:
             port = 5000

I have no idea if it is a bug. Maybe there are some documentations
elsewhere explain this.

Best,
Minglangjun Li

On Tue, Jul 14, 2015 at 9:34 AM, Xavier <somenxavier@gmail.com> wrote:

> But
>
> app.config['SERVER_NAME'] = '0.0.0.0:8000'
>
> is ignored (127.0.0.1:8000 is used)
>
> Why?
>
> On Tue, 14 Jul 2015 00:50:39 +0000
> Minglangjun Li <liminglangjun@gmail.com> ha escrit:
>
> > There isn't a 'port' option, what you need is 'SERVER_NAME'.
> > app.config['SERVER_NAME'] = '127.0.0.1:8000'
> >
> > Ref: http://flask.pocoo.org/docs/0.10/api/#application-object
> >
> > Best,
> > Minglangjun Li
> >
> > On 7/13/15, gideon namane <kpedronams@gmail.com> wrote:
> > > Hello I'm new to this too but how about you do....
> > > app.config.from_object(_name_)
> > > app.config['port']=8000
> > > On Jul 13, 2015 11:13 PM, "Xavier" <somenxavier@gmail.com> wrote:
> > >
> > >> Yeah I know I can pass 'port' option directly to app.run. But I want
> to
> > >> do
> > >> it (and also pass other things) thought config.
> > >>
> > >> Thanks for all,
> > >>
> > >>
> > >> On Mon, 13 Jul 2015 13:57:26 -0700
> > >> Mike Nickey <mnickey@gmail.com> ha escrit:
> > >>
> > >> > Just a precursor glance and it seems like this can be done in a
> > >> > different
> > >> > way. You can specify the port like so.
> > >> >
> > >> > if __name__ == '__main__':
> > >> >       app.run(host='0.0.0.0', port=80)
> > >> >
> > >> > The link source can be found here.
> > >> >
> > >>
> http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80
> > >> >
> > >> > If this doesn't work or other have a different idea please let me
> know.
> > >> I'm
> > >> > always ready to learn more.
> > >> >
> > >> > On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com>
> wrote:
> > >> >
> > >> > > Hi,
> > >> > >
> > >> > > I'm not be able to load configuration:
> > >> > >
> > >> > > from flask import Flask
> > >> > > app = Flask(__name__)
> > >> > >
> > >> > > app.config['port'] = 8000
> > >> > >
> > >> > > @app.route("/")
> > >> > > def hello():
> > >> > >     return "Hello World!"
> > >> > >
> > >> > > if __name__ == "__main__":
> > >> > >     app.run()
> > >> > >
> > >> > >
> > >> > >
> > >> > > This app serves itself in port 5000 not in 8000. Why? Perhaps a
> > >> > > simple
> > >> > > question but in the manual I could not get the answer.
> > >> > > Any help?
> > >> > >
> > >> > > Thanks in advance,
> > >> > > Xavier
> > >> > >
> > >> >
> > >> >
> > >> >
> > >> > --
> > >> > ~MEN
> > >>
> > >
>

Re: [flask] Config problems

From:
Xavier
Date:
2015-07-14 @ 12:11
Yes. It's a bug.

>         if server_name and ':' in server_name:
>              port = int(server_name.rsplit(':', 1)[1])

should be

>         if server_name and ':' in server_name:
>		host = server_name.rsplit(':', 1)[0])
>              port = int(server_name.rsplit(':', 1)[1])

If not, host is  not set.
Perhaps any developer could fix it.

Thanks Minglangjun

On Tue, 14 Jul 2015 11:49:47 +0000
Minglangjun Li <liminglangjun@gmail.com> ha escrit:

> Found the answer in the source code, *flask/app.py*
> 
>     if host is None:
>         host = '127.0.0.1'
>     if port is None:
>         server_name = self.config['SERVER_NAME']
>         if server_name and ':' in server_name:
>              port = int(server_name.rsplit(':', 1)[1])
>         else:
>              port = 5000
> 
> I have no idea if it is a bug. Maybe there are some documentations
> elsewhere explain this.
> 
> Best,
> Minglangjun Li
> 
> On Tue, Jul 14, 2015 at 9:34 AM, Xavier <somenxavier@gmail.com> wrote:
> 
> > But
> >
> > app.config['SERVER_NAME'] = '0.0.0.0:8000'
> >
> > is ignored (127.0.0.1:8000 is used)
> >
> > Why?
> >
> > On Tue, 14 Jul 2015 00:50:39 +0000
> > Minglangjun Li <liminglangjun@gmail.com> ha escrit:
> >
> > > There isn't a 'port' option, what you need is 'SERVER_NAME'.
> > > app.config['SERVER_NAME'] = '127.0.0.1:8000'
> > >
> > > Ref: http://flask.pocoo.org/docs/0.10/api/#application-object
> > >
> > > Best,
> > > Minglangjun Li
> > >
> > > On 7/13/15, gideon namane <kpedronams@gmail.com> wrote:
> > > > Hello I'm new to this too but how about you do....
> > > > app.config.from_object(_name_)
> > > > app.config['port']=8000
> > > > On Jul 13, 2015 11:13 PM, "Xavier" <somenxavier@gmail.com> wrote:
> > > >
> > > >> Yeah I know I can pass 'port' option directly to app.run. But I want
> > to
> > > >> do
> > > >> it (and also pass other things) thought config.
> > > >>
> > > >> Thanks for all,
> > > >>
> > > >>
> > > >> On Mon, 13 Jul 2015 13:57:26 -0700
> > > >> Mike Nickey <mnickey@gmail.com> ha escrit:
> > > >>
> > > >> > Just a precursor glance and it seems like this can be done in a
> > > >> > different
> > > >> > way. You can specify the port like so.
> > > >> >
> > > >> > if __name__ == '__main__':
> > > >> >       app.run(host='0.0.0.0', port=80)
> > > >> >
> > > >> > The link source can be found here.
> > > >> >
> > > >>
> > 
http://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80
> > > >> >
> > > >> > If this doesn't work or other have a different idea please let me
> > know.
> > > >> I'm
> > > >> > always ready to learn more.
> > > >> >
> > > >> > On Mon, Jul 13, 2015 at 1:46 PM, Xavier <somenxavier@gmail.com>
> > wrote:
> > > >> >
> > > >> > > Hi,
> > > >> > >
> > > >> > > I'm not be able to load configuration:
> > > >> > >
> > > >> > > from flask import Flask
> > > >> > > app = Flask(__name__)
> > > >> > >
> > > >> > > app.config['port'] = 8000
> > > >> > >
> > > >> > > @app.route("/")
> > > >> > > def hello():
> > > >> > >     return "Hello World!"
> > > >> > >
> > > >> > > if __name__ == "__main__":
> > > >> > >     app.run()
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> > > This app serves itself in port 5000 not in 8000. Why? Perhaps a
> > > >> > > simple
> > > >> > > question but in the manual I could not get the answer.
> > > >> > > Any help?
> > > >> > >
> > > >> > > Thanks in advance,
> > > >> > > Xavier
> > > >> > >
> > > >> >
> > > >> >
> > > >> >
> > > >> > --
> > > >> > ~MEN
> > > >>
> > > >
> >