librelist archives

« back to archive

KeyError: 'REQUEST_METHOD' when running Getting Started application on uwsgi

KeyError: 'REQUEST_METHOD' when running Getting Started application on uwsgi

From:
Hsu, Ryan
Date:
2013-04-15 @ 23:39
Hi All,

I'm wondering if anyone knows the source of the following error when I try
to run the Flask Getting Started application on Nginx uwsgi:

[pid: 20140|app: 0|req: 2/5]  () {16 vars in 361 bytes} [Mon Apr 15 
09:12:55 2013]   => generated 0 bytes in 2 msecs ( 500) 0 headers in 0 
bytes (0 switches on core 0)
Traceback (most recent call last):
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1685, in wsgi_app
    with self.request_context(environ):
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1646, in request_context
    return RequestContext(self, environ)
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/ctx.py",
line 166, in __init__
    self.url_adapter = app.create_url_adapter(self.request)
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1475, in create_url_adapter
   server_name=self.config['SERVER_NAME'])
  File 
"/usr/local/lib/python2.7/dist-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/routing.py",
line 1196, in bind_to_environ
    environ['REQUEST_METHOD'], environ.get('PATH_INFO'),
KeyError: 'REQUEST_METHOD'
[pid: 20141|app: 0|req: 4/6]  () {16 vars in 361 bytes} [Mon Apr 15 
09:12:55 2013]   => generated 0 bytes in 2 msecs ( 500) 0 headers in 0 
bytes (0 switches on core 0)

The app code (taken from the Flask web site)

from flask import Flask
application = Flask(__name__)

@application.route('/')
def hello():
        return 'hello'

My uwsgi configuration:

<uwsgi>
    <plugin>python</plugin>
    
<socket>/run/uwsgi/app/vm-mc-dilbert.asl.lab.bme.com/vm-mc-dilbert.asl.lab.bme.com.socket</socket>
    <pythonpath>/srv/www/vm-mc-dilbert.asl.lab.bme.com/application</pythonpath>
    <app mountpoint="/">
        <script>wsgi_configuration_module</script>
    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>


My Nginx config:

server {
    listen          80;
    server_name     vm-mc-dilbert;
    server_name     vm-mc-dilbert.asl.lab.bme.com;
    access_log      /srv/www/vm-mc-dilbert.asl.lab.bme.com/logs/access.log;
    error_log       /srv/www/vm-mc-dilbert.asl.lab.bme.com/logs/error.log;

    location / {
        uwsgi_pass      
unix:///run/uwsgi/app/vm-mc-dilbert.asl.lab.bme.com/vm-mc-dilbert.asl.lab.bme.com.socket;
    }

    location /static {
        root   /srv/www/vm-mc-dilbert.asl.lab.bme.com/public_html;
    }
}

Thank you,
Ryan

Re: [flask] KeyError: 'REQUEST_METHOD' when running Getting Started application on uwsgi

From:
薛 鹏飞
Date:
2013-04-16 @ 00:33
--
Sincerely,
Pengfei Xue
https://life-map.rhcloud.com

在 2013-4-16,上午7:39,"Hsu, Ryan" <Ryan.Hsu@emc.com> 写道:

> Hi All,
>  
> I’m wondering if anyone knows the source of the following error when I 
try to run the Flask Getting Started application on Nginx uwsgi:
>  
> [pid: 20140|app: 0|req: 2/5]  () {16 vars in 361 bytes} [Mon Apr 15 
09:12:55 2013]   => generated 0 bytes in 2 msecs ( 500) 0 headers in 0 
bytes (0 switches on core 0)
> Traceback (most recent call last):
>   File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1701, in __call__
>     return self.wsgi_app(environ, start_response)
>   File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1685, in wsgi_app
>     with self.request_context(environ):
>   File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1646, in request_context
>     return RequestContext(self, environ)
>   File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/ctx.py",
line 166, in __init__
>     self.url_adapter = app.create_url_adapter(self.request)
>   File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1475, in create_url_adapter
>    server_name=self.config['SERVER_NAME'])
>   File 
"/usr/local/lib/python2.7/dist-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/routing.py",
line 1196, in bind_to_environ
>     environ['REQUEST_METHOD'], environ.get('PATH_INFO'),
> KeyError: 'REQUEST_METHOD'
> [pid: 20141|app: 0|req: 4/6]  () {16 vars in 361 bytes} [Mon Apr 15 
09:12:55 2013]   => generated 0 bytes in 2 msecs ( 500) 0 headers in 0 
bytes (0 switches on core 0)
>  
> The app code (taken from the Flask web site)
>  
> from flask import Flask
> application = Flask(__name__)
>  
> @application.route('/')
> def hello():
>         return 'hello'
>  
> My uwsgi configuration:
>  
> <uwsgi>
>     <plugin>python</plugin>
>     
<socket>/run/uwsgi/app/vm-mc-dilbert.asl.lab.bme.com/vm-mc-dilbert.asl.lab.bme.com.socket</socket>
>     <pythonpath>/srv/www/vm-mc-dilbert.asl.lab.bme.com/application</pythonpath>
>     <app mountpoint="/">
>         <script>wsgi_configuration_module</script>
>     </app>
>     <master/>
>     <processes>4</processes>
>     <harakiri>60</harakiri>
>     <reload-mercy>8</reload-mercy>
>     <cpu-affinity>1</cpu-affinity>
>     <stats>/tmp/stats.socket</stats>
>     <max-requests>2000</max-requests>
>     <limit-as>512</limit-as>
>     <reload-on-as>256</reload-on-as>
>     <reload-on-rss>192</reload-on-rss>
>     <no-orphans/>
>     <vacuum/>
> </uwsgi>
>  
>  
> My Nginx config:
>  
> server {
>     listen          80;
>     server_name     vm-mc-dilbert;
>     server_name     vm-mc-dilbert.asl.lab.bme.com;
>     access_log      /srv/www/vm-mc-dilbert.asl.lab.bme.com/logs/access.log;
>     error_log       /srv/www/vm-mc-dilbert.asl.lab.bme.com/logs/error.log;
>  
>     location / {
>         uwsgi_pass      
unix:///run/uwsgi/app/vm-mc-dilbert.asl.lab.bme.com/vm-mc-dilbert.asl.lab.bme.com.socket;
>     }

i think in this location aka /,  you should include uwsgi_params; 

>  
>     location /static {
>         root   /srv/www/vm-mc-dilbert.asl.lab.bme.com/public_html;
>     }
> }
>  
> Thank you,
> Ryan
>  

Re: [flask] KeyError: 'REQUEST_METHOD' when running Getting Started application on uwsgi

From:
Hsu, Ryan
Date:
2013-04-16 @ 03:56
Thanks Pengfei, that solved the problem. From what I gathered, it looks 
like the purpose of "include uwsgi_param" is to pass some special request 
environment parameters from nginx to uwsgi which is then passed to the 
Flask application.

Regards,
Ryan



________________________________
From: flask@librelist.com [flask@librelist.com] on behalf of 薛 鹏飞 
[pengphy@gmail.com]
Sent: Monday, April 15, 2013 5:33 PM
To: flask@librelist.com
Subject: Re: [flask] KeyError: 'REQUEST_METHOD' when running Getting 
Started application on uwsgi


--
Sincerely,
Pengfei Xue
https://life-map.rhcloud.com<UrlBlockedError.aspx>

在 2013-4-16,上午7:39,"Hsu, Ryan" <Ryan.Hsu@emc.com<mailto:Ryan.Hsu@emc.com>> 写道:

Hi All,

I’m wondering if anyone know s the source of the following error when I 
try to run the Flask Getting Started application on Nginx uwsgi:

[pid: 20140|app: 0|req: 2/5]  () {16 vars in 361 bytes} [Mon Apr 15 
09:12:55 2013]   => generated 0 bytes in 2 msecs ( 500) 0 headers in 0 
bytes (0 switches on core 0)
Traceback (most recent call last):
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1685, in wsgi_app
    with self.request_context(environ):
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1646, in request_context
    return RequestContext(self, environ)
  File "/usr/loc 
al/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/ctx.py", line 
166, in __init__
    self.url_adapter = app.create_url_adapter(self.request)
  File 
"/usr/local/lib/python2.7/dist-packages/Flask-0.9-py2.7.egg/flask/app.py",
line 1475, in create_url_adapter
   server_name=self.config['SERVER_NAME'])
  File 
"/usr/local/lib/python2.7/dist-packages/Werkzeug-0.8.3-py2.7.egg/werkzeug/routing.py",
line 1196, in bind_to_environ
    environ['REQUEST_METHOD'], environ.get('PATH_INFO'),
KeyError: 'REQUEST_METHOD'
[pid: 20141|app: 0|req: 4/6]  () {16 vars in 361 bytes} [Mon Apr 15 
09:12:55 2013]   => generated 0 bytes in 2 msecs ( 500) 0 headers in 0 
bytes (0 switches on core 0)

The app code (taken from the Flask web site)

from flask import Flask
application = Flask(__name__)

@application.route('/')
def hello():
        return 'hello'

My uwsgi c onfiguration:

<uwsgi>
    <plugin>python</plugin>
    
<socket>/run/uwsgi/app/vm-mc-dilbert.asl.lab.bme.com/vm-mc-dilbert.asl.lab.bme.com.socket</socket>
    <pythonpath>/srv/www/vm-mc-dilbert.asl.lab.bme.com/application</pythonpath>
    <app mountpoint="/">
        <script>wsgi_configuration_module</script>
    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>


My Nginx config:

server {
    listen          80;
    server_name     vm-mc-dilbert;
    server_name     vm-mc-dilbert.asl.lab.bme.com;
    access_log      /srv/www/vm-mc-dilbert.asl.lab.bme.com/logs/access.log;
    error_log       /srv/www/vm-mc-dilbert.asl.lab.bme.com/logs/error.log;

    location / {
        uwsgi_pass      
unix:///run/uwsgi/app/vm-mc-dilbert.asl.lab.bme.com/vm-mc-dilbert.asl.lab.bme.com.socket<UrlBlockedError.aspx>;
    }

i think in this location aka /,  you should include uwsgi_params;


    location /static {
        root   /srv/www/vm-mc-dilbert.asl.lab.bme.com/public_html;
    }
}

Thank you,
Ryan
&n bsp;