For future users reading this thread... this means that the Iphone sent the 
JSON object POSTing to the page directly in the data stream, without "the 
usual" form encoding. For that, you can access what has been posted "in raw 
format" with request.body.read().

PS: Keep the code small

import gluon.contrib.simplejson as sj  #just if you don't have simplejson 
in python path
#in that case "import simplejson as sj" works
data = sj.loads(request.body.read())



On Wednesday, October 24, 2012 9:22:13 AM UTC+2, Mchurch wrote:
>
> import gluon.contrib.simplejson
>     data = gluon.contrib.simplejson.loads(request.body.read())
>
> That was the trick....
> Thank You  Niphlod, You put me in the right direction.
> IOS + WEB2PY = beautiful combination!!
> Mchurch
> Il giorno mercoledì 24 ottobre 2012 09:01:40 UTC+2, Mchurch ha scritto:
>>
>> Hi Niphlod, did You hope to be free of me so soon? :)
>> Looking at web2py errors, if i make a post request values are empty (not 
>> if i make a GET, but the final result is the same).
>> Using "CHARLES, web debugging proxy" i can see that data are dispatched 
>> with correct values and correct Content-Type (application/Json).
>> Im doing my best....
>>  
>>
>>
>>
>>
>> POST /Json/default/ricevo HTTP/1.1
>>  Host 127.0.0.1:8000  Accept */*  Accept-Encoding gzip  Content-Length 36  
>> Accept-Language en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, 
>> ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, 
>> ms, en-GB, ca, hu, vi, en-us;q=0.8  Content-Type application/json; 
>> charset=utf-8  Connection keep-alive  User-Agent mirko.json/1.0 
>> (unknown, iPhone OS 6.0, iPhone Simulator, Scale/1.000000)
>>   
>>
>> <type 'exceptions.TypeError'>(expected string or buffer)
>>>
>>> inspect attributes
>>>
>>>    - 
>>>    
>>>    *Function argument list
>>>    *(self=<json.decoder.JSONDecoder object>, s=<Storage {}>, 
>>>    _w=<built-in method match of _sre.SRE_Pattern object>)
>>>    
>>>    *Code listing
>>>    *
>>>    *Variables* 
>>>    - 
>>>    - 
>>>     
>>> *Context*
>>>
>>> locals
>>>
>>>  
>>>
>>> request
>>>
>>>  
>>>
>>> session
>>>
>>>  
>>>
>>> response
>>>
>>> locals
>>>   
>>> *s*
>>>  
>>> :
>>>  
>>> <Storage {}>
>>>   
>>> *self*
>>>  
>>> :
>>>  
>>> <json.decoder.JSONDecoder object>
>>>   
>>> request
>>>   
>>> *ajax*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *application*
>>>  
>>> :
>>>  
>>> Json
>>>   
>>> *args*
>>>  
>>> :
>>>  
>>>
>>>   *body*
>>>  
>>> :
>>>  
>>> <open file '<fdopen>', mode 'w+b' at 0x11c143c00>
>>>   
>>> *client*
>>>  
>>> :
>>>  
>>> 127.0.0.1
>>>   
>>> *controller*
>>>  
>>> :
>>>  
>>> default
>>>   
>>> *cookies*
>>>  
>>> :
>>>  
>>>
>>>   *env*
>>>  
>>> :
>>>    
>>> *app_folders*
>>>  
>>> :
>>>  
>>> set(['/Users/marcoMchurch/Sites/web2py/applications/Json/', 
>>> '/Users/marcoMchurch/Sites/web2py/applications/welcome/', 
>>> '/Users/marcoMchurch/Sites/web2py/applications/admin/'])
>>>   
>>> *applications_parent*
>>>  
>>> :
>>>  
>>> /.…../web2py
>>>   
>>> *cmd_args*
>>>  
>>> :
>>>  
>>>
>>>   *cmd_options*
>>>  
>>> :
>>>  
>>> <Values at 0x1104a53f8: {'verbose': False, 'ip': '127.0.0.1', 
>>> 'shutdown_timeout': 5, 'taskbar': False, 'nocron': False, 'pid_filename': 
>>> 'httpserver.pid', 'maxthreads': None, 'softcron': False, 'server_name': 
>>> 'marcos-', 'bpython': False, 'nogui': False, 'port': 8000, 'extcron': 
>>> False, 'debuglevel': 30, 'test': None, 'folder': 
>>> '/Users/marcoMchurch/Sites/web2py', 'config': '', 'import_models': False, 
>>> 'winservice': '', 'shell': None, 'run': '', 'log_filename': 
>>> 'httpserver.log', 'args': [''], 'socket_timeout': 1, 'ssl_ca_certificate': 
>>> None, 'scheduler': None, 'profiler_filename': None, 'ssl_private_key': '', 
>>> 'password': '<ask>', 'request_queue_size': 5, 'ssl_certificate': '', 
>>> 'cronjob': False, 'numthreads': None, 'quiet': False, 'interfaces': None, 
>>> 'minthreads': None, 'timeout': 10, 'plain': False, 'nobanner': False}>
>>>   
>>> *content_length*
>>>  
>>> :
>>>  
>>> 36
>>>   
>>> *content_type*
>>>  
>>> :
>>>  
>>> application/json; charset=utf-8
>>>   
>>> *db_sessions*
>>>  
>>> :
>>>  
>>> set([])
>>>   
>>> *debugging*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *gluon_parent*
>>>  
>>> :
>>>  
>>> ….web2py
>>>   
>>> *http_accept*
>>>  
>>> :
>>>  
>>> */*
>>>   
>>> *http_accept_encoding*
>>>  
>>> :
>>>  
>>> gzip
>>>   
>>> *http_accept_language*
>>>  
>>> :
>>>  
>>> en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, 
>>> zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, 
>>> hu, vi, en-us;q=0.8
>>>   
>>> *http_connection*
>>>  
>>> :
>>>  
>>> keep-alive
>>>   
>>> *http_content_length*
>>>  
>>> :
>>>  
>>> 36
>>>   
>>> *http_content_type*
>>>  
>>> :
>>>  
>>> application/json; charset=utf-8
>>>   
>>> *http_host*
>>>  
>>> :
>>>  
>>> 127.0.0.1:8000
>>>   
>>> *http_user_agent*
>>>  
>>> :
>>>  
>>> mirko.json/1.0 (unknown, iPhone OS 6.0, iPhone Simulator, Scale/1.000000)
>>>   
>>> *is_jython*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *is_pypy*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *path_info*
>>>  
>>> :
>>>  
>>> /Json/default/ricevo
>>>   
>>> *query_string*
>>>  
>>> :
>>>  
>>>
>>>   *remote_addr*
>>>  
>>> :
>>>  
>>> 127.0.0.1
>>>   
>>> *remote_port*
>>>  
>>> :
>>>  
>>> 60150
>>>   
>>> *request_method*
>>>  
>>> :
>>>  
>>> POST
>>>   
>>> *script_name*
>>>  
>>> :
>>>  
>>>
>>>   *server_name*
>>>  
>>> :
>>>  
>>> marcos-……
>>>   
>>> *server_port*
>>>  
>>> :
>>>  
>>> 8000
>>>   
>>> *server_protocol*
>>>  
>>> :
>>>  
>>> HTTP/1.1
>>>   
>>> *server_software*
>>>  
>>> :
>>>  
>>> Rocket 1.2.4
>>>   
>>> *web2py_crontype*
>>>  
>>> :
>>>  
>>> hard
>>>   
>>> *web2py_path*
>>>  
>>> :
>>>  
>>> /Users/marcoMchurch/Sites/web2py
>>>   
>>> *web2py_version*
>>>  
>>> :
>>>    
>>> 1
>>>   
>>> 99
>>>   
>>> 4
>>>   
>>> datetime.datetime(2011, 12, 14, 14, 46, 14)
>>>   
>>> stable
>>>     
>>> *wsgi_errors*
>>>  
>>> :
>>>  
>>> <open file '<stderr>', mode 'w' at 0x10f7b2270>
>>>   
>>> *wsgi_file_wrapper*
>>>  
>>> :
>>>  
>>> <class wsgiref.util.FileWrapper at 0x1103c1328>
>>>   
>>> *wsgi_input*
>>>  
>>> :
>>>  
>>> <socket._fileobject object at 0x117971950>
>>>   
>>> *wsgi_multiprocess*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *wsgi_multithread*
>>>  
>>> :
>>>  
>>> True
>>>   
>>> *wsgi_run_once*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *wsgi_url_scheme*
>>>  
>>> :
>>>  
>>> http
>>>   
>>> *wsgi_version*
>>>  
>>> :
>>>    
>>> 1
>>>   
>>> 0
>>>       
>>> *extension*
>>>  
>>> :
>>>  
>>> html
>>>   
>>> *folder*
>>>  
>>> :
>>>  
>>> /Users/marcoMchurch/Sites/web2py/applications/Json/
>>>   
>>> *function*
>>>  
>>> :
>>>  
>>> ricevo
>>>   
>>> *get_vars*
>>>  
>>> :
>>>  
>>>
>>>   *global_settings*
>>>  
>>> :
>>>    
>>> *app_folders*
>>>  
>>> :
>>>  
>>> set(['/Users/marcoMchurch/Sites/web2py/applications/Json/', 
>>> '/Users/marcoMchurch/Sites/web2py/applications/welcome/', 
>>> '/Users/marcoMchurch/Sites/web2py/applications/admin/'])
>>>   
>>> *applications_parent*
>>>  
>>> :
>>>  
>>> /Users/marcoMchurch/Sites/web2py
>>>   
>>> *cmd_args*
>>>  
>>> :
>>>  
>>>
>>>   *cmd_options*
>>>  
>>> :
>>>  
>>> <Values at 0x1104a53f8: {'verbose': False, 'ip': '127.0.0.1', 
>>> 'shutdown_timeout': 5, 'taskbar': False, 'nocron': False, 'pid_filename': 
>>> 'httpserver.pid', 'maxthreads': None, 'softcron': False, 'server_name': '
>>> marcos-imac.homenet.telecomitalia.it', 'bpython': False, 'nogui': 
>>> False, 'port': 8000, 'extcron': False, 'debuglevel': 30, 'test': None, 
>>> 'folder': '/Users/marcoMchurch/Sites/web2py', 'config': '', 
>>> 'import_models': False, 'winservice': '', 'shell': None, 'run': '', 
>>> 'log_filename': 'httpserver.log', 'args': [''], 'socket_timeout': 1, 
>>> 'ssl_ca_certificate': None, 'scheduler': None, 'profiler_filename': None, 
>>> 'ssl_private_key': '', 'password': '<ask>', 'request_queue_size': 5, 
>>> 'ssl_certificate': '', 'cronjob': False, 'numthreads': None, 'quiet': 
>>> False, 'interfaces': None, 'minthreads': None, 'timeout': 10, 'plain': 
>>> False, 'nobanner': False}>
>>>   
>>> *db_sessions*
>>>  
>>> :
>>>  
>>> set([])
>>>   
>>> *debugging*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *gluon_parent*
>>>  
>>> :
>>>  
>>> /Users/marcoMchurch/Sites/web2py
>>>   
>>> *is_jython*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *is_pypy*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *web2py_crontype*
>>>  
>>> :
>>>  
>>> hard
>>>   
>>> *web2py_version*
>>>  
>>> :
>>>    
>>> 1
>>>   
>>> 99
>>>   
>>> 4
>>>   
>>> datetime.datetime(2011, 12, 14, 14, 46, 14)
>>>   
>>> stable
>>>       
>>> *is_https*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *is_local*
>>>  
>>> :
>>>  
>>> True
>>>   
>>> *is_restful*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *now*
>>>  
>>> :
>>>  
>>> datetime.datetime(2012, 10, 23, 23, 37, 12, 447022)
>>>   
>>> *post_vars*
>>>  
>>> :
>>>  
>>>
>>>   *url*
>>>  
>>> :
>>>  
>>> /Json/default/ricevo
>>>   
>>> *utcnow*
>>>  
>>> :
>>>  
>>> datetime.datetime(2012, 10, 23, 21, 37, 12, 447035)
>>>   
>>> *uuid*
>>>  
>>> :
>>>  
>>> Json/127.0.0.1.2012-10-23.23-37-12.35f491ef-469f-421f-93e9-0cebff13da2f
>>>   
>>> *vars*
>>>  
>>> :
>>>  
>>>
>>>   *wsgi*
>>>  
>>> :
>>>    
>>> *environ*
>>>  
>>> :
>>>    
>>> *CONTENT_LENGTH*
>>>  
>>> :
>>>  
>>> 36
>>>   
>>> *CONTENT_TYPE*
>>>  
>>> :
>>>  
>>> application/json; charset=utf-8
>>>   
>>> *HTTP_ACCEPT*
>>>  
>>> :
>>>  
>>> */*
>>>   
>>> *HTTP_ACCEPT_ENCODING*
>>>  
>>> :
>>>  
>>> gzip
>>>   
>>> *HTTP_ACCEPT_LANGUAGE*
>>>  
>>> :
>>>  
>>> en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, 
>>> zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, 
>>> hu, vi, en-us;q=0.8
>>>   
>>> *HTTP_CONNECTION*
>>>  
>>> :
>>>  
>>> keep-alive
>>>   
>>> *HTTP_CONTENT_LENGTH*
>>>  
>>> :
>>>  
>>> 36
>>>   
>>> *HTTP_CONTENT_TYPE*
>>>  
>>> :
>>>  
>>> application/json; charset=utf-8
>>>   
>>> *HTTP_HOST*
>>>  
>>> :
>>>  
>>> 127.0.0.1:8000
>>>   
>>> *HTTP_USER_AGENT*
>>>  
>>> :
>>>  
>>> mirko.json/1.0 (unknown, iPhone OS 6.0, iPhone Simulator, Scale/1.000000)
>>>   
>>> *PATH_INFO*
>>>  
>>> :
>>>  
>>> /Json/default/ricevo
>>>   
>>> *QUERY_STRING*
>>>  
>>> :
>>>  
>>>
>>>   *REMOTE_ADDR*
>>>  
>>> :
>>>  
>>> 127.0.0.1
>>>   
>>> *REMOTE_PORT*
>>>  
>>> :
>>>  
>>> 60150
>>>   
>>> *REQUEST_METHOD*
>>>  
>>> :
>>>  
>>> POST
>>>   
>>> *SCRIPT_NAME*
>>>  
>>> :
>>>  
>>>
>>>   *SERVER_NAME*
>>>  
>>> :
>>>  
>>> marcos-……
>>>   
>>> *SERVER_PORT*
>>>  
>>> :
>>>  
>>> 8000
>>>   
>>> *SERVER_PROTOCOL*
>>>  
>>> :
>>>  
>>> HTTP/1.1
>>>   
>>> *SERVER_SOFTWARE*
>>>  
>>> :
>>>  
>>> Rocket 1.2.4
>>>   
>>> *wsgi.errors*
>>>  
>>> :
>>>  
>>> <open file '<stderr>', mode 'w' at 0x10f7b2270>
>>>   
>>> *wsgi.file_wrapper*
>>>  
>>> :
>>>  
>>> <class wsgiref.util.FileWrapper at 0x1103c1328>
>>>   
>>> *wsgi.input*
>>>  
>>> :
>>>  
>>> <open file '<fdopen>', mode 'w+b' at 0x11c143c00>
>>>   
>>> *wsgi.multiprocess*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *wsgi.multithread*
>>>  
>>> :
>>>  
>>> True
>>>   
>>> *wsgi.run_once*
>>>  
>>> :
>>>  
>>> False
>>>   
>>> *wsgi.url_scheme*
>>>  
>>> :
>>>  
>>> http
>>>   
>>> *wsgi.version*
>>>  
>>> :
>>>  
>>> 1
>>>       
>>> IN FILE: 
>>> /USERS/MARCOMchurch/SITES/WEB2PY/APPLICATIONS/JSON/CONTROLLERS/DEFAULT.PY
>>>   
>>> 1.
>>>
>>> 2.
>>>
>>> 3.
>>>
>>> 4.
>>>
>>> 5.
>>>
>>> 6.
>>>
>>> 7.
>>>
>>> 8.
>>>
>>> 9.
>>>
>>> 10.
>>>
>>> 11.
>>>
>>> 12.
>>>
>>> 13.
>>>
>>> 14.
>>>
>>> 15.
>>>
>>> 16.
>>>
>>> 17.
>>>
>>> 18.
>>>
>>>
>>>  *# -*- coding: utf-8 -*-*
>>>
>>> *# this file is released under public domain and you can use without 
>>> limitations*
>>>
>>> **
>>>
>>> *
>>> #########################################################################
>>> *
>>>
>>> *## This is a samples controller*
>>>
>>> *## - index is the default action of any application*
>>>
>>> *## - user is required for authentication and authorization*
>>>
>>> *## - download is for downloading files uploaded in the db (does 
>>> streaming)*
>>>
>>> *## - call exposes all registered services (none by default)*
>>>
>>> *
>>> #########################################################################
>>> *
>>>
>>> *……*
>>>
>>> *def *ricevo*():*
>>>
>>> *    **from *json *import *loads*, *dumps
>>>
>>>     data *=  
>>> *loads*(*request<http://127.0.0.1:8000/examples/global/vars/request>
>>> *.*vars*)*
>>>
>>> *    **print *data
>>>
>>>     *print *request <http://127.0.0.1:8000/examples/global/vars/request>
>>> *.*vars*.*body*.*read*()*
>>>
>>> *    **print *request<http://127.0.0.1:8000/examples/global/vars/request>
>>> *.*vars
>>>
>>>     *return *dumps*(*data*)*
>>>   
>>
>> Il giorno martedì 23 ottobre 2012 17:55:34 UTC+2, Niphlod ha scritto:
>>>
>>> almost dinner time here.... :P
>>>
>>> On Tuesday, October 23, 2012 5:44:45 PM UTC+2, Mchurch wrote:
>>>>
>>>> I'll try, thanks.
>>>> Ps. Did You eat some snakes for breakfast?....
>>>> :)
>>>
>>>

-- 



Reply via email to