On Sunday, November 4, 2018 at 5:06:33 AM UTC-8, Carl Hunter Roach wrote:
>
> As suspected, my workaround was to URL encode the "offending" fields at
> the client end. simpleton.loads() then parsed the json happily. The field
> could then be "unencoded".
>
> My system has plenty of json passing between clients and the Web2py
> service. I can't work out why I've tripped over here.
>
>
If that value is Base64 encoded, the "=" is a part of the encoding that is
used for padding when the length of the original string doesn't fill the
last set of encoding bytes (looking at WP for Base64, len(S) % 4 != 0).
/dps
>
> On Saturday, 3 November 2018 19:04:20 UTC, Carl Hunter Roach wrote:
>>
>> I've had a stable web2py-based service for some years now.
>> But it broke today with a small change in a data value - that's my
>> working hypothesis.
>>
>> The output of the print statement (see code below):
>>
>> <Storage
>> {'{"sort":"relevancy","longitude":-0.1228710438544765,"keywords":"parrot","latitude":51.51158325978085,"page_cursor":"A2ebAAFVVvv0OW53MHyzU0VWVVBxb0tiUW9oWkd0UHMzU09aUjIwYUFBPT0jMTA':
>>
>> '"}'}>
>>
>>
>> The value of "page_cursor" sent by the caller is "page_cursor" :
>> "A2ebAAFVVvv0OW53MHyzU0VWVVBxb0tiUW9oWkd0UHMzU09aUjIwYUFBPT0jMTA=' i.e.
>> there is an "=" suffix. But by the time my controller receives the
>> json structure the "=" has been mangled. This obviously defeats the
>> simplejson loads function as the data is no longer valid json. Previous to
>> today page_cursor values have been more straightforward and not included a
>> "=" character and the code has executed fine.
>>
>> Any suggestions? A fix or a different approach to parsing
>> request.post_vars
>>
>> The call is to: https://…/api/v1/article_search
>>
>> The code excerpts:
>>
>> app/controller.py
>>
>> @articles_service.json
>> def get_article():
>> from applications.app.modules.article import get_articles
>> print(request.post_vars)
>> return get_articles(request.post_vars)
>>
>> app/modules/article.py
>>
>> def get_articles(json_fields):
>> '''
>> get with a JSON interface
>> '''
>> from gluon.contrib.simplejson import loads
>> fields = {}
>> for i in json_fields.keys():
>> fields = loads(i) # crashes here.
>> return …
>>
>> routes.py
>>
>> routes_in = ( ('/api/v1/$anything',
>> '/app/controller/call/json/$anything') )
>> routes_out = [(x, y) for (y, x) in routes_in]
>>
>>
>>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.