librelist archives

« back to archive

string parameter containing = sign

string parameter containing = sign

From:
Mellan, Alain
Date:
2014-10-17 @ 00:01
Whenever I have an argument that contain an = sign, the request comes back
as InvalidRequestError: Invalid Request.

For example:

My server is a simple echo service:

import flask
import flask_jsonrpc

app = flask.Flask(__name__)
jsonrpc = flask_jsonrpc.JSONRPC(app, '/api')

@jsonrpc.method('echo(src=str)')
def echo(src):
    return src

app.run('localhost', port=5000, debug=True)

This call works as expected:

curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params": 
{"src":"foobar"}, "id":"1"}' http://localhost:5000/api

This one does not:

curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params": {"src": 
"foo=bar"}, "id":"1"}' http://localhost:5000/api

I really need to send through some string parameters where the string 
contains '='.

I'm using Flask 0.10.1.  Is this a bug or a feature? What I am missing?

Thanks!

-- alain.

Re: [flask] string parameter containing = sign

From:
Charles
Date:
2014-10-17 @ 03:24
On Fri, Oct 17, 2014 at 7:01 AM, Mellan, Alain <amellan@qti.qualcomm.com> wrote:
> curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params": {"src":
> "foo=bar"}, "id":"1"}' http://localhost:5000/api

Just encode the data

curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params":
{"src":"foo%3Dbar"}, "id":"1"}' http://localhost:5000/api

Re: [flask] string parameter containing = sign

From:
Mellan, Alain
Date:
2014-10-17 @ 14:51
Thank you, that's what I'm doing as a workaround, but this defeats the 
whole purpose of JSON-RPC if I have to serialize some JSON and encode it.

Is there a reason why the JSON that comes out of Flask has been 
transformed already before it gets to Flask_jsonrpc? 

-- alain.

On Oct 16, 2014, at 20:24 , Charles <peacech@gmail.com> wrote:

On Fri, Oct 17, 2014 at 7:01 AM, Mellan, Alain <amellan@qti.qualcomm.com> wrote:
> curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params": {"src":
> "foo=bar"}, "id":"1"}' http://localhost:5000/api

Just encode the data

curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params":
{"src":"foo%3Dbar"}, "id":"1"}' http://localhost:5000/api

Re: [flask] string parameter containing = sign

From:
Mellan, Alain
Date:
2014-10-17 @ 21:35
Well, the issue turned out to be in the jsonrpc implementation I was using
that was not urlencoding the serialized JSON properly. I'm using 
jsonrpclib now and things are fine.

-- alain.

-----Original Message-----
From: Mellan, Alain 
Sent: Friday, October 17, 2014 13:40
To: flask@librelist.com
Subject: RE: [flask] string parameter containing = sign

I traced the issue back to Werkzeug. See 
https://github.com/mitsuhiko/werkzeug/issues/613.

Does it mean that every string that goes through JSONRPC should be 
urlencoded? It seems it is defeating the purpose of JSONRPC. Am I missing 
something?

-- alain.

-----Original Message-----
From: Mellan, Alain 
Sent: Friday, October 17, 2014 7:51
To: flask@librelist.com
Subject: Re: [flask] string parameter containing = sign

Thank you, that's what I'm doing as a workaround, but this defeats the 
whole purpose of JSON-RPC if I have to serialize some JSON and encode it.

Is there a reason why the JSON that comes out of Flask has been 
transformed already before it gets to Flask_jsonrpc? 

-- alain.

On Oct 16, 2014, at 20:24 , Charles <peacech@gmail.com> wrote:

On Fri, Oct 17, 2014 at 7:01 AM, Mellan, Alain <amellan@qti.qualcomm.com> wrote:
> curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params": {"src":
> "foo=bar"}, "id":"1"}' http://localhost:5000/api

Just encode the data

curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params":
{"src":"foo%3Dbar"}, "id":"1"}' http://localhost:5000/api

Re: [flask] string parameter containing = sign

From:
Mellan, Alain
Date:
2014-10-17 @ 20:39
I traced the issue back to Werkzeug. See 
https://github.com/mitsuhiko/werkzeug/issues/613.

Does it mean that every string that goes through JSONRPC should be 
urlencoded? It seems it is defeating the purpose of JSONRPC. Am I missing 
something?

-- alain.

-----Original Message-----
From: Mellan, Alain 
Sent: Friday, October 17, 2014 7:51
To: flask@librelist.com
Subject: Re: [flask] string parameter containing = sign

Thank you, that's what I'm doing as a workaround, but this defeats the 
whole purpose of JSON-RPC if I have to serialize some JSON and encode it.

Is there a reason why the JSON that comes out of Flask has been 
transformed already before it gets to Flask_jsonrpc? 

-- alain.

On Oct 16, 2014, at 20:24 , Charles <peacech@gmail.com> wrote:

On Fri, Oct 17, 2014 at 7:01 AM, Mellan, Alain <amellan@qti.qualcomm.com> wrote:
> curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params": {"src":
> "foo=bar"}, "id":"1"}' http://localhost:5000/api

Just encode the data

curl -i -X POST -d '{"jsonrpc":"2.0", "method": "echo", "params":
{"src":"foo%3Dbar"}, "id":"1"}' http://localhost:5000/api

routing question

From:
Jörg Bönisch
Date:
2014-10-19 @ 00:21
I'm trying to do @app.route('/<path:path>/<string:filename>')

If I call it with "/foo/bar.html", it does not work, but with 
"/foo/bar.<anything else but html>" it works.
What am I missing?

Re: [flask] routing question

From:
Mehmet Taşkıner
Date:
2014-10-19 @ 12:05
You have to render some template, or send an html from static. 

    return send_from_directory(app.static_folder, request.path[1:])

In order to that you have to define app object like this:

app = Flask(__name__, static_folder='static', static_url_path='/static’)

Correct me if I’m wrong.

> On 19 Oct 2014, at 03:21, Jörg Bönisch <joerg@joergwork.org> wrote:
> 
> I'm trying to do @app.route('/<path:path>/<string:filename>')
> 
> If I call it with "/foo/bar.html", it does not work, but with 
> "/foo/bar.<anything else but html>" it works.
> What am I missing?
> 
> 

Re: [flask] [solved] routing question

From:
Jörg Bönisch
Date:
2014-10-19 @ 15:12
Thanks for your input.
In fact, it was just an caching issue from my FF.
And no, that is not a static html file. Just wanted the url looking like 
one.

Am 19.10.2014 um 14:05 schrieb Mehmet Taşkıner:
> You have to render some template, or send an html from static.
>
>      return send_from_directory(app.static_folder, request.path[1:])
>
> In order to that you have to define app object like this:
>
> app = Flask(__name__, static_folder='static', static_url_path='/static’)
>
> Correct me if I’m wrong.
>
>> On 19 Oct 2014, at 03:21, Jörg Bönisch <joerg@joergwork.org> wrote:
>>
>> I'm trying to do @app.route('/<path:path>/<string:filename>')
>>
>> If I call it with "/foo/bar.html", it does not work, but with
>> "/foo/bar.<anything else but html>" it works.
>> What am I missing?
>>
>>