librelist archives

« back to archive

Flask is seen POST as GET

Flask is seen POST as GET

From:
Marcio Andrey Oliveira
Date:
2014-03-11 @ 15:25
Hi.

I'm making some tests with flask and I'm getting a weird error.

I submit a post to flask and it sees as a GET. Am I missing something?

Below is the code used.

# -------------------------------
#submit.html
# -------------------------------
<html>
<head></head>
<body>
    <form action="http://maoserver.com/gp" method="post">
            data: <input name="data" type="text" value="mydata" />
            <input name="mySubmit" type="submit" value="submit" />
        </form>
</body>
</html>



# -------------------------------
# app/__init__.py
# -------------------------------
import logging
from logging.handlers import RotatingFileHandler

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)

from app.views import views
from app.models import models


formatter = logging.Formatter( "%(asctime)s;%(levelname)s;%(message)s" )
handler = RotatingFileHandler('logs/common.log', maxBytes=10000,
backupCount=1)
handler.setLevel(logging.INFO)
handler.setFormatter(formatter)
app.logger.addHandler(handler)



# -------------------------------
# app/views/views.py
# -------------------------------
from logging.handlers import RotatingFileHandler
import sys

from flask import Flask
from flask import request
from app import app
from app.models import models

@app.route('/')
@app.route('/index')
def index():
    app.logger.error( request.url + ';' + request.method + ';' +
request.query_string + ';' + request.remote_addr + ';' +
request.headers.get('User-Agent') )
    return "you're in the index"


@app.route('/gp', methods=['POST', 'GET'])
@app.route('/gp/', methods=['POST', 'GET'])
def gp():
    if request.method != 'POST':
        app.logger.warn( request.url + ';' + request.method + ';' +
request.query_string + ';' + request.remote_addr + ';' +
request.headers.get('User-Agent') )
        return 'OK. I get it.'
    else:
        app.logger.warn( request.url + ';' + request.method + ';' +
request.query_string + ';' + request.remote_addr + ';' +
request.headers.get('User-Agent') )
        enc = request.form['data']



Log file shows the following:
2014-03-11 
11:29:12,450;WARNING;http://maoserver.com/gp/;*GET*;;200.160.84.75;Mozilla/5.0
(X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0

Moreover, if I use the Apache's ab as follow
ab -c 1 -n 1 -v4  -p tests/gp_post_data.txt  -T
application/x-www-form-urlencoded   http://maoserver.com/gp/

the log shows
2014-03-11 11:31:19,204;WARNING;http://maoserver.com/gp/;*GET*
;;200.160.75.128;ApacheBench/2.3


If I change the code from app/views/views.py

@app.route('/gp', methods=['POST', 'GET'])
@app.route('/gp/', methods=['POST', 'GET'])

to

@app.route('/gp', methods=['POST'])
@app.route('/gp/', methods=['POST'])

I get the response

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>


If change the code of the of app/views/views.py to try to ignore the method
used and to read the post parameters, as show bellow

@app.route('/gp', methods=['POST', 'GET'])
@app.route('/gp/', methods=['POST', 'GET'])
def gp():
        app.logger.warn( request.url + ';' + request.method + ';' +
request.query_string + ';' + request.remote_addr + ';' +
request.headers.get('User-Agent') )
        try:
            enc = request.form['data']
        except:
            app.logger.error ( sys.exc_info()[0] )
            return ''

I get the following error :

2014-03-11 12:09:36,253;ERROR;<class
'werkzeug.exceptions.BadRequestKeyError'>


My environment:
CentOS (6.5)
Passenger (4.0.3)
Flask (0.10.1)
Flask-SQLAlchemy (1.0)
iniparse (0.3.1)
itsdangerous (0.23)
Jinja2 (2.7.2)
MarkupSafe (0.18)
mercurial (1.4)
MySQL-python (1.2.5)
pycurl (7.19.0)
SQLAlchemy (0.9.3)
urlgrabber (3.9.1)
Werkzeug (0.9.4)


The same ab command line above works fine on a site made with Sinatra (that
just have routes for POST methods) so I'm sure it's correct. Also the code
from HTML page above should send a post.


Any help is very much appreciated.

Regards.

-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games

<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*

*Get free games for*

<http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>

Re: [flask] Flask is seen POST as GET

From:
Farhan
Date:
2014-03-11 @ 15:57
Hi Marcio,

Note the following:

1. In your submit.html: change the URL to use {{ url_for(‘gp’) }}
2. Strip away all logging code, and run the app as a simple Flask app.
3. You view method should always return a Response. As listed, they are 
not, this may be an oversight when pasting code, but in any case, make 
sure your are returning a Response.
4. Pick better names for your modules and things, event for sample and 
test apps, it makes hunting for bugs like this a lot easier. And I’m 
pretty sure it will resolve your issue if the app was not named ‘app’.

After all of that, your template and view code work as expected. That is 
to say, when the form is submitted, it is properly POSTed when the URL is 
hit directly a GET is request is made.

On Mar 11, 2014, at 8:25 AM, Marcio Andrey Oliveira <plicatibu@gmail.com> wrote:

> Hi.
> 
> I'm making some tests with flask and I'm getting a weird error.
> 
> I submit a post to flask and it sees as a GET. Am I missing something?
> 
> Below is the code used.
> 
> # -------------------------------
> #submit.html
> # -------------------------------
> <html>
> <head></head>
> <body>
>     <form action="http://maoserver.com/gp" method="post">
>             data: <input name="data" type="text" value="mydata" />
>             <input name="mySubmit" type="submit" value="submit" />
>         </form>
> </body>
> </html>
> 
> 
> 
> # -------------------------------
> # app/__init__.py
> # -------------------------------
> import logging
> from logging.handlers import RotatingFileHandler
> 
> from flask import Flask
> from flask.ext.sqlalchemy import SQLAlchemy
> 
> app = Flask(__name__)
> app.config.from_object('config')
> db = SQLAlchemy(app)
> 
> from app.views import views
> from app.models import models
> 
> 
> formatter = logging.Formatter( "%(asctime)s;%(levelname)s;%(message)s" )
> handler = RotatingFileHandler('logs/common.log', maxBytes=10000, backupCount=1)
> handler.setLevel(logging.INFO)
> handler.setFormatter(formatter)
> app.logger.addHandler(handler)
> 
> 
> 
> # -------------------------------
> # app/views/views.py
> # -------------------------------
> from logging.handlers import RotatingFileHandler
> import sys
> 
> from flask import Flask
> from flask import request
> from app import app
> from app.models import models
> 
> @app.route('/')
> @app.route('/index')
> def index():
>     app.logger.error( request.url + ';' + request.method + ';' + 
request.query_string + ';' + request.remote_addr + ';' + 
request.headers.get('User-Agent') )
>     return "you're in the index"
> 
> 
> @app.route('/gp', methods=['POST', 'GET'])
> @app.route('/gp/', methods=['POST', 'GET'])
> def gp():
>     if request.method != 'POST':
>         app.logger.warn( request.url + ';' + request.method + ';' + 
request.query_string + ';' + request.remote_addr + ';' + 
request.headers.get('User-Agent') )
>         return 'OK. I get it.'
>     else:
>         app.logger.warn( request.url + ';' + request.method + ';' + 
request.query_string + ';' + request.remote_addr + ';' + 
request.headers.get('User-Agent') )
>         enc = request.form['data']
> 
> 
> 
> Log file shows the following:
> 2014-03-11 
11:29:12,450;WARNING;http://maoserver.com/gp/;GET;;200.160.84.75;Mozilla/5.0
(X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0
> 
> Moreover, if I use the Apache's ab as follow
> ab -c 1 -n 1 -v4  -p tests/gp_post_data.txt  -T 
application/x-www-form-urlencoded   http://maoserver.com/gp/
> 
> the log shows
> 2014-03-11 
11:31:19,204;WARNING;http://maoserver.com/gp/;GET;;200.160.75.128;ApacheBench/2.3
> 
> 
> If I change the code from app/views/views.py
> 
> @app.route('/gp', methods=['POST', 'GET'])
> @app.route('/gp/', methods=['POST', 'GET'])
> 
> to
> 
> @app.route('/gp', methods=['POST'])
> @app.route('/gp/', methods=['POST'])
> 
> I get the response
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
> <title>405 Method Not Allowed</title>
> <h1>Method Not Allowed</h1>
> <p>The method is not allowed for the requested URL.</p>
> 
> 
> If change the code of the of app/views/views.py to try to ignore the 
method used and to read the post parameters, as show bellow 
> 
> @app.route('/gp', methods=['POST', 'GET'])
> @app.route('/gp/', methods=['POST', 'GET'])
> def gp():
>         app.logger.warn( request.url + ';' + request.method + ';' + 
request.query_string + ';' + request.remote_addr + ';' + 
request.headers.get('User-Agent') )
>         try:
>             enc = request.form['data']
>         except:
>             app.logger.error ( sys.exc_info()[0] )
>             return ''
> 
> I get the following error :
> 
> 2014-03-11 12:09:36,253;ERROR;<class 'werkzeug.exceptions.BadRequestKeyError'>
> 
> 
> My environment:
> CentOS (6.5)
> Passenger (4.0.3)
> Flask (0.10.1)
> Flask-SQLAlchemy (1.0)
> iniparse (0.3.1)
> itsdangerous (0.23)
> Jinja2 (2.7.2)
> MarkupSafe (0.18)
> mercurial (1.4)
> MySQL-python (1.2.5)
> pycurl (7.19.0)
> SQLAlchemy (0.9.3)
> urlgrabber (3.9.1)
> Werkzeug (0.9.4)
> 
> 
> The same ab command line above works fine on a site made with Sinatra 
(that just have routes for POST methods) so I'm sure it's correct. Also 
the code from HTML page above should send a post.
> 
> 
> Any help is very much appreciated.
> 
> Regards.
> 
> -- 
> Do you have an arcade site? I do 1:1 Game Exchange
> 
> Play free on-line games
> 
> Get free games for
> 
> 
> 
> 

Re: [flask] Flask is seen POST as GET

From:
Marcio Andrey Oliveira
Date:
2014-03-11 @ 17:03
Farhan, thank you so much for taking your time to help me.

1. The submit.html file is not part of the project. It's a plain HTML I
created and opened it using Firefox just to submit test data to flask.
That's the reason it's using the full URL instead of {{ url_for('gp') }}.

2. I removed all logging code (even though I don't see how it could
interfere in the result).

3. My view always return a response. A copy n paste error in my previous
email doesn't how it. :)

4. I renamed the package from app to flasktest and module app was renamed
to mao in order to have different names. I restarted the application (touch
tmp/restart.txt) but I still have the same problem.

Using a page (submit.html) or the ab (as shown in previous email) I'm sure
I'm effectively sending a POST.

The full source code is not more than what I showed because I first want to
be sure I can receive data sent by POST and only after that I'm going to
add any action (like saving to database).

Best regards.




2014-03-11 12:57 GMT-03:00 Farhan <inshany@gmail.com>:

> Hi Marcio,
>
> Note the following:
>
> 1. In your submit.html: change the URL to use {{ url_for('gp') }}
> 2. Strip away all logging code, and run the app as a simple Flask app.
> 3. You view method should always return a Response. As listed, they are
> not, this may be an oversight when pasting code, but in any case, make sure
> your are returning a Response.
> 4. Pick better names for your modules and things, event for sample and
> test apps, it makes hunting for bugs like this a lot easier. And I'm pretty
> sure it will resolve your issue if the app was not named 'app'.
>
> After all of that, your template and view code work as expected. That is
> to say, when the form is submitted, it is properly PO STed when the URL is
> hit directly a GET is request is made.
>
> On Mar 11, 2014, at 8:25 AM, Marcio Andrey Oliveira <plicatibu@gmail.com>
> wrote:
>
> Hi.
>
> I'm making some tests with flask and I'm getting a weird error.
>
> I submit a post to flask and it sees as a GET. Am I missing something?
>
> Below is the code used.
>
> # -------------------------------
> #submit.html
> # -------------------------------
> <html>
> <head></head>
> <body>
>     <form action="http://maoserver.com/gp" method="post">
>             data: <input name="data" type="text" value="mydata" />
>             <input name="mySubmit" type="submit" value="submit" />
>         </form>
> </body>
> </html>
>
>
>
> # -------------------------------
> # app/__init__.py
> # -------------------------------
> import logging
> from logging.handlers import RotatingFileHandler
>
> from flask import Flask
> from flask.ext.sqlalchemy import SQLAlchemy
>
> app = Flask(__name__)
> app.config.from_object('config')
> db = SQLAlchemy(app)
>
> from app.views import views
> from app.models import models
>
>
> formatter = logging.Formatter( "%(asctime)s;%(levelname)s;%(message)s" )
> handler = RotatingFileHandler('logs/common.log', maxBytes=10000,
> backupCount=1)
> handler.setLevel(logging.INFO)
> handler.setFormatter(formatter)
> app.logger.addHandler(handler)
>
>
>
> # -------------------------------
> # app/views/views.py
> # -------------------------------
> from logging.handlers import RotatingFileHandler
> import sys
>
> from flask import Flask
> from flask import request
> from app import app
> from app.models import models
>
> @app.route('/')
> @app.route('/index')
> def index():
>     app.logger.error( request.url + ';' + request.method + ';' +
> request.query_string + ';' + request.remote_addr + ';' +
> request.headers.get('User-Agent') )
>     return "you're in the index"
>
>
> @app.route('/gp', methods=['POST', 'GET'])
> @app.route('/gp/', methods=['POST', 'GET'])
> def gp():
>     if request.method != 'POST':
>         app.logger.warn( request.url + ';' + request.method + ';' +
> request.query_string + ';' + request.remote_addr + ';' +
> request.headers.get('User-Agent') )
>         return 'OK. I get it.'
>     else:
>         app.logger.warn( request.url + ';' + request.method + ';' +
> request.query_string + ';' + request.remote_addr + ';' +
> request.headers.get('User-Agent') )
>         enc = request.form['data']
>
>
>
> Log file shows the following:
> 2014-03-11 
11:29:12,450;WARNING;http://maoserver.com/gp/;*GET*;;200.160.84.75;Mozilla/5.0
> (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0
>
> Moreover, if I use the Apache's ab as follow
> ab -c 1 -n 1 -v4  -p tests/gp_post_data.txt  -T
> application/x-www-form-urlencoded   http://maoserver.com/gp/
>
> the log shows
> 2014-03-11 11:31:19,204;WARNING;http://maoserver.com/gp/;*GET*
> ;;200.160.75.128;ApacheBench/2.3
>
>
> If I change the code from app/views/views.py
>
> @app.route('/gp', methods=['POST', 'GET'])
> @app.route('/gp/', methods=['POST', 'GET'])
>
> to
>
> @app.route('/gp', methods=['POST'])
> @app.route('/gp/', methods=['POST'])
>
> I get the response
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
> <title>405 Method Not Allowed</title>
> <h1>Method Not Allowed</h1>
> <p>The method is not allowed for the requested URL.</p>
>
>
> If change the code of the of app/views/views.py to try to ignore the
> method used and to read the post parameters, as show bellow
>
> @app.route('/gp', methods=['POST', 'GET'])
> @app.route('/gp/', methods=['POST', 'GET'])
> def gp():
>         app.logger.warn( request.url + ';' + request.method + ';' +
> request.query_string + ';' + request.remote_addr + ';' +
> request.headers.get('User-Agent') )
>         try:
>             enc = request.form['data']
>         except:
>             app.logger.error ( sys.exc_info()[0] )
>             return ''
>
> I get the following error :
>
> 2014-03-11 12:09:36,253;ERROR;<class
> 'werkzeug.exceptions.BadRequestKeyError'>
>
>
> My environment:
> CentOS (6.5)
> Passenger (4.0.3)
> Flask (0.10.1)
> Flask-SQLAlchemy (1.0)
> iniparse (0.3.1)
> itsdangerous (0.23)
> Jinja2 (2.7.2)
> MarkupSafe (0.18)
> mercurial (1.4)
> MySQL-python (1.2.5)
> pycurl (7.19.0)
> SQLAlchemy (0.9.3)
> urlgrabber (3.9.1)
> Werkzeug (0.9.4)
>
>
> The same ab command line above works fine on a site made with Sinatra
> (that just have routes for POST methods) so I'm sure it's correct. Also the
> code from HTML page above should send a post.
>
>
> Any help is very much appreciated.
>
> Regards.
>
> --
>
>
> *Do you have an arcade site? I do 1:1 Game Exchange *
> *Play free on-line games
> 
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*
>
> *Get free games for*
>
> <http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
>
>
>
>


-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games

<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*

*Get free games for*

<http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>

Re: [flask] Flask is seen POST as GET

From:
gioi
Date:
2014-03-11 @ 17:03
Il 11/03/2014 16:57, Farhan ha scritto:
> Hi Marcio,
>
> Note the following:
>
> 1. In your submit.html: change the URL to use {{ url_for(‘gp’) }}
Better but not needed.
> 2. Strip away all logging code,
Not needed.
> and run the app as a simple Flask app.
You mean using development server?
> 3. You view method should always return a Response. As listed, they
> are not, this may be an oversight when pasting code, but in any case,
> make sure your are returning a Response.
Not needed (it can return text, for example). `return "something"`
should work.
> 4. Pick better names for your modules and things, event for sample and
> test apps, it makes hunting for bugs like this a lot easier. And I’m
> pretty sure it will resolve your issue if the app was not named ‘app’.
I completely agree, even if I always called my app `app` and never had
any problem.
>
> After all of that, your template and view code work as expected. That
> is to say, when the form is submitted, it is properly POSTed when the
> URL is hit directly a GET is request is made.

Can you give us some more details? For example: Flask & Python version,
deployment mode and server...

Re: [flask] Flask is seen POST as GET

From:
Marcio Andrey Oliveira
Date:
2014-03-11 @ 17:11
Hi.

I'm using Apache / Pushion Passenger to run the flask application.

My environment:

CentOS (6.5)
Passenger (4.0.3)
Flask (0.10.1)
Flask-SQLAlchemy (1.0)
iniparse (0.3.1)
itsdangerous (0.23)
Jinja2 (2.7.2)
MarkupSafe (0.18)
mercurial (1.4)
MySQL-python (1.2.5)
pycurl (7.19.0)
SQLAlchemy (0.9.3)
urlgrabber (3.9.1)
Werkzeug (0.9.4)

Regards.


2014-03-11 14:03 GMT-03:00 gioi <g@gioi.tk>:

> Il 11/03/2014 16:57, Farhan ha scritto:
> > Hi Marcio,
> >
> > Note the following:
> >
> > 1. In your submit.html: change the URL to use {{ url_for('gp') }}
> Better but not needed.
> > 2. Strip away all logging code,
> Not needed.
> > and run the app as a simple Flask app.
> You mean using development server?
> > 3. You view method should always return a Response. As listed, they
> > are not, this may be an oversight when pasting code, but in any case,
> > make sure your are returning a Response.
> Not needed (it can return text, for example). `return "something"`
> should work.
> > 4. Pick better names for your modules and things, event for sample and
> > test apps, it makes hunting for bugs like this a lot easier. And I'm
> > pretty sure it will resolve your issue if the app was not named 'app'.
> I completely agree, even if I always called my app `app` and never had
> any problem.
> >
> > After all of that, your template and view code work as expected. That
> > is to say, when the form is submitted, it is properly POSTed when the
> > URL is hit directly a GET is request is made.
>
> Can you give us some more details? For example: Flask & Python version,
> deployment mode and server...
>
>


-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games

<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*

*Get free games for*

<http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>

Re: [flask] Flask is seen POST as GET

From:
Ian Bentley
Date:
2014-03-11 @ 17:40
The fast that the apache log shows it as a GET means that it's probably
getting sent from the browser as a get.

Is there any javascript on the index.html page that might be affecting this?

Can you try curling the URL?


On 11 March 2014 13:11, Marcio Andrey Oliveira <plicatibu@gmail.com> wrote:

> Hi.
>
> I'm using Apache / Pushion Passenger to run the flask application.
>
> My environment:
>
> CentOS (6.5)
> Passenger (4.0.3)
> Flask (0.10.1)
> Flask-SQLAlchemy (1.0)
> iniparse (0.3.1)
> itsdangerous (0.23)
> Jinja2 (2.7.2)
> MarkupSafe (0.18)
> mercurial (1.4)
> MySQL-python (1.2.5)
> pycurl (7.19.0)
> SQLAlchemy (0.9.3)
> urlgrabber (3.9.1)
> Werkzeug (0.9.4)
>
> Regards.
>
>
> 2014-03-11 14:03 GMT-03:00 gioi <g@gioi.tk>:
>
> Il 11/03/2014 16:57, Farhan ha scritto:
>> > Hi Marcio,
>> >
>> > Note the following:
>> >
>> > 1. In your submit.html: change the URL to use {{ url_for(‘gp’) }}
>> Better but not needed.
>> > 2. Strip away all logging code,
>> Not needed.
>> > and run the app as a simple Flask app.
>> You mean using development server?
>> > 3. You view method should always return a Response. As listed, they
>> > are not, this may be an oversight when pasting code, but in any case,
>> > make sure your are returning a Response.
>> Not needed (it can return text, for example). `return "something"`
>> should work.
>> > 4. Pick better names for your modules and things, event for sample and
>> > test apps, it makes hunting for bugs like this a lot easier. And I’m
>> > pretty sure it will resolve your issue if the app was not named ‘app’.
>> I completely agree, even if I always called my app `app` and never had
>> any problem.
>> >
>> > After all of that, your template and view code work as expected. That
>> > is to say, when the form is submitted, it is properly POSTed when the
>> > URL is hit directly a GET is request is made.
>>
>> Can you give us some more details? For example: Flask & Python version,
>> deployment mode and server...
>>
>>
>
>
> --
>
>
> *Do you have an arcade site? I do 1:1 Game Exchange *
> *Play free on-line games
> 
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*
>
> *Get free games for*
>
> <http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
>
>
>


-- 
Ian Bentley

Re: [flask] Flask is seen POST as GET

From:
Marcio Andrey Oliveira
Date:
2014-03-11 @ 19:42
Ian,

the Apache's log shows nothing. The logs I'm getting from my own
application (see the first post).

I used the curl as you suggested (*curl --data "data=mydata"
http://maoserver.com/gp/ <http://maoserver.com/gp/>*) and it worked fine.

I also noticed that when I call the URL using the trailing slash it
works (*http://maoserver.com/gp
<http://maoserver.com/gp>/*) but if I don't use it then I get the following
response from flask

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="
http://test01.yas.plicatibu.com/gp/">http://test01.yas.plicatibu.com/gp/</a>.
If not click the link

I changed the code from submit form to include the trailing slash in the
URL and it worked too. It seems that when there is no trailing slash the
flask is asking for a redirection and this redirection is being issued as
an GET.

# original submit.html (appears as GET)
<html>
<head></head>
<body>
    <form action="*http://maoserver.com/gp <http://maoserver.com/gp>*"
method="post">
            data: <input name="data" type="text" value="mydata" />
            <input name="mySubmit" type="submit" value="submit" />
        </form>
</body>
</html>

# new submit.html (appears as POST)
<html>
<head></head>
<body>
    <form action="*http://maoserver.com/gp <http://maoserver.com/gp>/*"
method="post">
            data: <input name="data" type="text" value="mydata" />
            <input name="mySubmit" type="submit" value="submit" />
        </form>
</body>
</html>

My route is as follow:
@mao.route('/gp', methods=['POST', 'GET'])
@mao.route('/gp/', methods=['POST', 'GET'])

I think it's not the best way to handle the optional trailing slash in URL
but it's a problem I'll work latter on.

The use of curl helped me to figure out what was happening.

Thank you all for the help.

I really appreciate that.

Best regards.



2014-03-11 14:40 GMT-03:00 Ian Bentley <ian.bentley@gmail.com>:

> The fast that the apache log shows it as a GET means that it's probably
> getting sent from the browser as a get.
>
> Is there any javascript on the index.html page that might be affecting
> this?
>
> Can you try curling the URL?
>
>
> On 11 March 2014 13:11, Marcio Andrey Oliveira <plicatibu@gmail.com>wrote:
>
>> Hi.
>>
>> I'm using Apache / Pushion Passenger to run the flask application.
>>
>> My environment:
>>
>> CentOS (6.5)
>> Passenger (4.0.3)
>> Flask (0.10.1)
>> Flask-SQLAlchemy (1.0)
>> iniparse (0.3.1)
>> itsdangerous (0.23)
>> Jinja2 (2.7.2)
>> MarkupSafe (0.18)
>> mercurial (1.4)
>> MySQL-python (1.2.5)
>> pycurl (7.19.0)
>> SQLAlchemy (0.9.3)
>> urlgrabber (3.9.1)
>> Werkzeug (0.9.4)
>>
>> Regards.
>>
>>
>> 2014-03-11 14:03 GMT-03:00 gioi <g@gioi.tk>:
>>
>> Il 11/03/2014 16:57, Farhan ha scritto:
>>> > Hi Marcio,
>>> >
>>> > Note the following:
>>> >
>>> > 1. In your submit.html: change the URL to use {{ url_for('gp') }}
>>> Better but not needed.
>>> > 2. Strip away all logging code,
>>> Not needed.
>>> > and run the app as a simple Flask app.
>>> You mean using development server?
>>> > 3. You view method should always return a Response. As listed, they
>>> > are not, this may be an oversight when pasting code, but in any case,
>>> > make sure your are returning a Response.
>>> Not needed (it can return text, for example). `return "something"`
>>> should work.
>>> > 4. Pick better names for your modules and things, event for sample and
>>> > test apps, it makes hunting for bugs like this a lot easier. And I'm
>>> > pretty sure it will resolve your issue if the app was not named 'app'.
>>> I completely agree, even if I always called my app `app` and never had
>>> any problem.
>>> >
>>> > After all of that, your template and view code work as expected. That
>>> > is to say, when the form is submitted, it is properly POSTed when the
>>> > URL is hit directly a GET is request is made.
>>>
>>> Can you give us some more details? For example: Flask & Python version,
>>> deployment mode and server...
>>>
>>>
>>
>>
>> --
>>
>>
>> *Do you have an arcade site? I do 1:1 Game Exchange *
>> *Play free on-line games
>> 
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*
>>
>> *Get free games for*
>>
>> <http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
>>
>>
>>
>
>
> --
> Ian Bentley
>



-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games

<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*

*Get free games for*

<http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>

Re: [flask] Flask is seen POST as GET

From:
Ian Bentley
Date:
2014-03-11 @ 19:52
You should read the "Unique URLs / Redirection Behavior" section of
http://flask.pocoo.org/docs/quickstart/#routing

It will explain the behaviour you are seeing.


On 11 March 2014 15:42, Marcio Andrey Oliveira <plicatibu@gmail.com> wrote:

> Ian,
>
> the Apache's log shows nothing. The logs I'm getting from my own
> application (see the first post).
>
> I used the curl as you suggested (*curl --data "data=mydata"
> http://maoserver.com/gp/ <http://maoserver.com/gp/>*) and it worked fine.
>
> I also noticed that when I call the URL using the trailing slash it 
works (*http://maoserver.com/gp
> <http://maoserver.com/gp>/*) but if I don't use it then I get the
> following response from flask
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
> <title>Redirecting...</title>
> <h1>Redirecting...</h1>
> <p>You should be redirected automatically to target URL: <a href="
> http://test01.yas.plicatibu.com/gp/">http://test01.yas.plicatibu.com/gp/</a>.
> If not click the link
>
> I changed the code from submit form to include the trailing slash in the
> URL and it worked too. It seems that when there is no trailing slash the
> flask is asking for a redirection and this redirection is being issued as
> an GET.
>
> # original submit.html (appears as GET)
>
> <html>
> <head></head>
> <body>
>     <form action="*http://maoserver.com/gp <http://maoserver.com/gp>*"
> method="post">
>             data: <input name="data" type="text" value="mydata" />
>             <input name="mySubmit" type="submit" value="submit" />
>         </form>
> </body>
> </html>
>
> # new submit.html (appears as POST)
> <html>
> <head></head>
> <body>
>     <form action="*http://maoserver.com/gp <http://maoserver.com/gp>/*"
> method="post">
>
>             data: <input name="data" type="text" value="mydata" />
>             <input name="mySubmit" type="submit" value="submit" />
>         </form>
> </body>
> </html>
>
>
> My route is as follow:
> @mao.route('/gp', methods=['POST', 'GET'])
> @mao.route('/gp/', methods=['POST', 'GET'])
>
> I think it's not the best way to handle the optional trailing slash in URL
> but it's a problem I'll work latter on.
>
> The use of curl helped me to figure out what was happening.
>
> Thank you all for the help.
>
> I really appreciate that.
>
> Best regards.
>
>
>
> 2014-03-11 14:40 GMT-03:00 Ian Bentley <ian.bentley@gmail.com>:
>
> The fast that the apache log shows it as a GET means that it's probably
>> getting sent from the browser as a get.
>>
>> Is there any javascript on the index.html page that might be affecting
>> this?
>>
>> Can you try curling the URL?
>>
>>
>> On 11 March 2014 13:11, Marcio Andrey Oliveira <plicatibu@gmail.com>wrote:
>>
>>> Hi.
>>>
>>> I'm using Apache / Pushion Passenger to run the flask application.
>>>
>>> My environment:
>>>
>>> CentOS (6.5)
>>> Passenger (4.0.3)
>>> Flask (0.10.1)
>>> Flask-SQLAlchemy (1.0)
>>> iniparse (0.3.1)
>>> itsdangerous (0.23)
>>> Jinja2 (2.7.2)
>>> MarkupSafe (0.18)
>>> mercurial (1.4)
>>> MySQL-python (1.2.5)
>>> pycurl (7.19.0)
>>> SQLAlchemy (0.9.3)
>>> urlgrabber (3.9.1)
>>> Werkzeug (0.9.4)
>>>
>>> Regards.
>>>
>>>
>>> 2014-03-11 14:03 GMT-03:00 gioi <g@gioi.tk>:
>>>
>>> Il 11/03/2014 16:57, Farhan ha scritto:
>>>> > Hi Marcio,
>>>> >
>>>> > Note the following:
>>>> >
>>>> > 1. In your submit.html: change the URL to use {{ url_for(‘gp’) }}
>>>> Better but not needed.
>>>> > 2. Strip away all logging code,
>>>> Not needed.
>>>> > and run the app as a simple Flask app.
>>>> You mean using development server?
>>>> > 3. You view method should always return a Response. As listed, they
>>>> > are not, this may be an oversight when pasting code, but in any case,
>>>> > make sure your are returning a Response.
>>>> Not needed (it can return text, for example). `return "something"`
>>>> should work.
>>>> > 4. Pick better names for your modules and things, event for sample and
>>>> > test apps, it makes hunting for bugs like this a lot easier. And I’m
>>>> > pretty sure it will resolve your issue if the app was not named ‘app’.
>>>> I completely agree, even if I always called my app `app` and never had
>>>> any problem.
>>>> >
>>>> > After all of that, your template and view code work as expected. That
>>>> > is to say, when the form is submitted, it is properly POSTed when the
>>>> > URL is hit directly a GET is request is made.
>>>>
>>>> Can you give us some more details? For example: Flask & Python version,
>>>> deployment mode and server...
>>>>
>>>>
>>>
>>>
>>> --
>>>
>>>
>>> *Do you have an arcade site? I do 1:1 Game Exchange *
>>> *Play free on-line games
>>> 
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*
>>>
>>> *Get free games for*
>>>
>>> <http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
>>>
>>>
>>>
>>
>>
>> --
>> Ian Bentley
>>
>
>
>
> --
>
>
> *Do you have an arcade site? I do 1:1 Game Exchange *
> *Play free on-line games
> 
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*
>
> *Get free games for*
>
> <http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
>
>
>


-- 
Ian Bentley

Re: [flask] Flask is seen POST as GET

From:
Marcio Andrey Oliveira
Date:
2014-03-11 @ 20:56
I'll read it carefully.

Thank you.


2014-03-11 16:52 GMT-03:00 Ian Bentley <ian.bentley@gmail.com>:

> You should read the "Unique URLs / Redirection Behavior" section of
> http://flask.pocoo.org/docs/quickstart/#routing
>
> It will explain the behaviour you are seeing.
>
>
> On 11 March 2014 15:42, Marcio Andrey Oliveira <plicatibu@gmail.com>wrote:
>
>> Ian,
>>
>> the Apache's log shows nothing. The logs I'm getting from my own
>> application (see the first post).
>>
>> I used the curl as you suggested (*curl --data "data=mydata"
>> http://maoserver.com/gp/ <http://maoserver.com/gp/>*) and it worked fine.
>>
>> I also noticed that when I call the URL using the trailing slash it works
>> (*http://maoserver.com/gp <http://maoserver.com/gp>/*) but if I don't
>> use it then I get the following response from flask
>>
>>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
>> <title>Redirecting...</title>
>> <h1>Redirecting...</h1>
>> <p>You should be redirected automatically to target URL: <a href="
>> http://test01.yas.plicatibu.com/gp/">http://test01.yas.plicatibu.com/gp/</a>.
>> If not click the link
>>
>> I changed the code from submit form to include the trailing slash in the
>> URL and it worked too. It seems that when there is no trailing slash the
>> flask is asking for a redirection and this redirection is being issued as
>> an GET.
>>
>> # original submit.html (appears as GET)
>>
>> <html>
>> <head></head>
>> <body>
>>     <form action="*http://maoserver.com/gp <http://maoserver.com/gp>*"
>> method="post">
>>             data: <input name="data" type="text" value="mydata" />
>>             <input name="mySubmit" type="submit" value="submit" />
>>         </form>
>> </body>
>> </html>
>>
>> # new submit.html (appears as POST)
>> <html>
>> <head></head>
>> <body>
>>     <form action="*http://maoserver.com/gp <http://maoserver.com/gp>/*"
>> method="post">
>>
>>             data: <input name="data" type="text" value="mydata" />
>>             <input name="mySubmit" type="submit" value="submit" />
>>         </form>
>> </body>
>> </html>
>>
>>
>> My route is as follow:
>> @mao.route('/gp', methods=['POST', 'GET'])
>> @mao.route('/gp/', methods=['POST', 'GET'])
>>
>> I think it's not the best way to handle the optional trailing slash in
>> URL but it's a problem I'll work latter on.
>>
>> The use of curl helped me to figure out what was happening.
>>
>> Thank you all for the help.
>>
>> I really appreciate that.
>>
>> Best regards.
>>
>>
>>
>> 2014-03-11 14:40 GMT-03:00 Ian Bentley <ian.bentley@gmail.com>:
>>
>> The fast that the apache log shows it as a GET means that it's probably
>>> getting sent from the browser as a get.
>>>
>>> Is there any javascript on the index.html page that might be affecting
>>> this?
>>>
>>> Can you try curling the URL?
>>>
>>>
>>> On 11 March 2014 13:11, Marcio Andrey Oliveira <plicatibu@gmail.com>wrote:
>>>
>>>> Hi.
>>>>
>>>> I'm using Apache / Pushion Passenger to run the flask application.
>>>>
>>>> My environment:
>>>>
>>>> CentOS (6.5)
>>>> Passenger (4.0.3)
>>>> Flask (0.10.1)
>>>> Flask-SQLAlchemy (1.0)
>>>> iniparse (0.3.1)
>>>> itsdangerous (0.23)
>>>> Jinja2 (2.7.2)
>>>> MarkupSafe (0.18)
>>>> mercurial (1.4)
>>>> MySQL-python (1.2.5)
>>>> pycurl (7.19.0)
>>>> SQLAlchemy (0.9.3)
>>>> urlgrabber (3.9.1)
>>>> Werkzeug (0.9.4)
>>>>
>>>> Regards.
>>>>
>>>>
>>>> 2014-03-11 14:03 GMT-03:00 gioi <g@gioi.tk>:
>>>>
>>>> Il 11/03/2014 16:57, Farhan ha scritto:
>>>>> > Hi Marcio,
>>>>> >
>>>>> > Note the following:
>>>>> >
>>>>> > 1. In your submit.html: change the URL to use {{ url_for('gp') }}
>>>>> Better but not needed.
>>>>> > 2. Strip away all logging code,
>>>>> Not needed.
>>>>> > and run the app as a simple Flask app.
>>>>> You mean using development server?
>>>>> > 3. You view method should always return a Response. As listed, they
>>>>> > are not, this may be an oversight when pasting code, but in any case,
>>>>> > make sure your are returning a Response.
>>>>> Not needed (it can return text, for example). `return "something"`
>>>>> should work.
>>>>> > 4. Pick better names for your modules and things, event for sample
>>>>> and
>>>>> > test apps, it makes hunting for bugs like this a lot easier. And I'm
>>>>> > pretty sure it will resolve your issue if the app was not named
>>>>> 'app'.
>>>>> I completely agree, even if I always called my app `app` and never had
>>>>> any problem.
>>>>> >
>>>>> > After all of that, your template and view code work as expected. That
>>>>> > is to say, when the form is submitted, it is properly POSTed when the
>>>>> > URL is hit directly a GET is request is made.
>>>>>
>>>>> Can you give us some more details? For example: Flask & Python version,
>>>>> deployment mode and server...
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>>
>>>>
>>>> *Do you have an arcade site? I do 1:1 Game Exchange *
>>>> *Play free on-line games
>>>> 
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*
>>>>
>>>> *Get free games for*
>>>>
>>>> <http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Ian Bentley
>>>
>>
>>
>>
>> --
>>
>>
>> *Do you have an arcade site? I do 1:1 Game Exchange *
>> *Play free on-line games
>> 
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*
>>
>> *Get free games for*
>>
>> <http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
>>
>>
>>
>
>
> --
> Ian Bentley
>



-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games

<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*

*Get free games for*

<http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>