[REST] encoding character in query patterns

107 views
Skip to first unread message

Mamisoa Andriantafika

unread,
Apr 23, 2016, 4:48:29 PM4/23/16
to web2py-users
Hi,

Using this usual REST code in controller :

def api_users():
    response
.view = 'generic.json' # or 'generic.' + request.extension
   
def GET(*args,**vars):
        patterns
= [
           
"/user[auth_user]",
           
"/user/{auth_user.id}",
           
"/user/{auth_user.id}/:field",
           
"/user/{auth_user.first_name.contains}/{auth_user.last_name.contains}/{auth_user.dob_pid7.eq}"
           
]
        db
.auth_user.created_by.readable = db.auth_user.modified_by.readable = db.auth_user.created_on.readable = db.auth_user.modified_on.readable = True
        parser
= db.parse_as_rest(patterns, args, vars)
        data
= parser.response
       
if parser.status == 200:
           
return dict(content=data)
       
else:
           
raise HTTP(parser.status, parser.error)

with the last pattern, if I use character with accent e.g:

/user/maït/lié

the query do not find match as it is not interpreted as:

"ma\u00eft" for first vars and
"li\u00e9" for the second vars

which is the encoding I find when I do the request /user/ma/li .

How can I correct the encoding transcription so that the request comply to the format:

/user/maï/lié

?

Mike



Richard Vézina

unread,
Apr 23, 2016, 5:57:21 PM4/23/16
to web2py-users
What I don't understand is why to get those without the u''

>>> print u"ma\u00eft"
maït

>>> print u"ma\u00eft".encode('utf8')
maït

>>> u"ma\u00eft".encode('utf8')
'ma\xc3\xaft'

Inside web2py it should be : 'ma\xc3\xaft'

So I am not sure where the string that you mention come from these two :


"ma\u00eft" for first vars and
"li\u00e9" for the second vars

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mamisoa Andriantafika

unread,
Apr 23, 2016, 8:38:01 PM4/23/16
to web2py-users
Just to be clearer, here is a response from the following get:


https
://localhost/test/default/api_users/user/ma/li/1978-01-01




{"content": [{"birth_country_pid23": "France", "first_name":
"Ma\u00eft", "last_name": "Li\u00e9", "modified_by": null,
"id": 42, "gender_pid8": 2, "created_by": null, "birth_town_pid23":
"Paris", "ssn_pid19": "", "created_on": "2016-04-23 15:59:49",
"modified_on": "2016-04-23 15:59:49", "maiden_name_pid6":
"Li\u00e9", "idc_num": "", "dob_pid7": "1978-01-01"}]}


but if I add the search with the accent:


https
://localhost/test/default/api_users/user/maï/lié/1978-01-01




{"content": []}




??

Richard Vézina

unread,
Apr 24, 2016, 8:57:23 AM4/24/16
to web2py-users
I don't understrand... Are you trying to generate this URL or you receive the request? Does it fails for a request you receive?

Mamisoa Andriantafika

unread,
Apr 24, 2016, 11:28:25 AM4/24/16
to web2py-users
The goal is to receive the right result from the query in the GET request.

As you saw, in the first query I get the result of the user that where first name, name and dob correspond to the parameters.

But when I had the accented character, I cannot get the expected same result.

From the first response, one can see that the query may have been done in UTF8. So I think that I should feed the GET request with a kind of UTF8 encoded characters, although I'm already in UTF8?

Richard Vézina

unread,
Apr 25, 2016, 12:01:00 PM4/25/16
to web2py-users
I think it comes from here :


As RestParse is used here :


By parse_as_rest()

RestParse don't seems to support unicode URL yet...

You may consider open an issue here :


If someone (Massimo or Giovanni) can confirmed this...

Thanks

Richard

Richard Vézina

unread,
Apr 26, 2016, 9:32:41 AM4/26/16
to web2py-users
@Massimo... Look here!!

Richard

Leonel Câmara

unread,
Apr 26, 2016, 11:05:52 AM4/26/16
to web2py-users
You need to url encode those characters. Have you tried that?

Richard Vézina

unread,
Apr 26, 2016, 1:17:20 PM4/26/16
to web2py-users
@Leonel, he receives unicode characters which are parsed and result with no record in case those special characters are include in the REST query... There is not really any way to url_encode has he not generate unicode URL...

Richard

On Tue, Apr 26, 2016 at 11:05 AM, Leonel Câmara <leonel...@gmail.com> wrote:
You need to url encode those characters. Have you tried that?

--

Richard Vézina

unread,
Apr 26, 2016, 1:18:02 PM4/26/16
to web2py-users
Also URL(url_encode=True) is default...

Mamisoa Andriantafika

unread,
Apr 26, 2016, 4:32:47 PM4/26/16
to web2py-users
Hi,

I did try but still not working.

Leonel Câmara

unread,
Apr 26, 2016, 6:16:39 PM4/26/16
to web...@googlegroups.com
You cannot have unicode characters in the path of an URL that is not a valid URL. If percent encoded path components do not work then it is a bug/missing feature. If you submit an issue in github I could look at it.

Mamisoa Andriantafika

unread,
Apr 27, 2016, 9:11:02 AM4/27/16
to web2py-users
Thank you I will do post an issue.

Richard Vézina

unread,
Apr 27, 2016, 10:06:29 AM4/27/16
to web2py-users

--
Reply all
Reply to author
Forward
0 new messages