Ok, this is what I had to do in order to get the headers to work over RPC,
since it can't serialize file objects and things like that:
@service.xmlrpc
@service.jsonrpc
def headers():
"""
Returns the request headers.
@return: request headers as dict.
"""
h = dict(**request.env)
for k, v in h.items():
if not isinstance(v, (str, set, list, dict, tuple, int, float)):
del h[k]
if isinstance(v, set):
h[k] = list(v)
return h
Now, when I run the RPC services, this is what I get WITHOUT Auth (sorry, I
couldn't find a good way to format this):
{u'content_length': u'57', u'debugging': False, u'http_user_agent':
u'jsonrpclib/0.1 (Python 2.7.1)', u'content_type': u'application/json-rpc',
u'script_name': '', u'server_protocol': u'HTTP/1.1', u'cmd_args': [],
u'web2py_path': u'/media/psf/Python/web2py', u'wsgi_url_scheme': u'https',
u'server_name': u'dev', u'remote_addr': u'172.16.100.173', u'is_jython':
False, u'applications_parent': u'/media/psf/Python/web2py', u'wsgi_version':
[1, 0], u'request_method': u'POST', u'web2py_original_uri':
u'/rpc_test/default/call/jsonrpc', u'server_port': u'8000',
u'http_content_type': u'application/json-rpc', u'http_accept_encoding':
u'gzip', u'wsgi_multithread': True, u'https': u'on', u'gluon_parent':
u'/media/psf/Python/web2py', u'server_software': u'Rocket 1.2.4',
u'web2py_version': u'Version 1.99.0 (2011-09-13 08:34:37)\n', u'http_host':
u'172.16.100.111:8000', u'wsgi_multiprocess': False, u'http_content_length':
u'57', u'request_uri': u'/rpc_test/default/call/jsonrpc', u'remote_port':
u'64982', u'app_folders': [u'/media/psf/Python/web2py/applications/admin/',
u'/media/psf/Python/web2py/applications/rpc_test/'], u'db_sessions': [],
u'query_string': '', u'wsgi_run_once': False, u'path_info':
u'/rpc_test/default/call/jsonrpc'}
{'content_length': '101', 'debugging': False, 'http_user_agent':
'xmlrpclib.py/1.0.1 (by www.pythonware.com)', 'http_content_length': '101',
'script_name': '', 'server_protocol': 'HTTP/1.1', 'cmd_args': [],
'web2py_path': '/media/psf/Python/web2py', 'wsgi_url_scheme': 'https',
'server_name': 'dev', 'remote_addr': '172.16.100.173', 'is_jython': False,
'applications_parent': '/media/psf/Python/web2py', 'wsgi_version': [1, 0],
'request_method': 'POST', 'web2py_original_uri':
'/rpc_test/default/call/xmlrpc', 'server_port': '8000', 'http_content_type':
'text/xml', 'http_accept_encoding': 'gzip', 'wsgi_multithread': True,
'https': 'on', 'gluon_parent': '/media/psf/Python/web2py',
'server_software': 'Rocket 1.2.4', 'web2py_version': 'Version 1.99.0
(2011-09-13 08:34:37)\n', 'http_host': '172.16.100.111:8000',
'wsgi_multiprocess': False, 'content_type': 'text/xml', 'request_uri':
'/rpc_test/default/call/xmlrpc', 'remote_port': '64984', 'app_folders':
['/media/psf/Python/web2py/applications/admin/',
'/media/psf/Python/web2py/applications/rpc_test/'], 'db_sessions': [],
'query_string': '', 'wsgi_run_once': False, 'path_info':
'/rpc_test/default/call/xmlrpc'}
And WITH Auth:
{u'content_length': u'57', u'debugging': False, u'http_user_agent':
u'jsonrpclib/0.1 (Python 2.7.1)', u'content_type': u'application/json-rpc',
u'script_name': '', u'server_protocol': u'HTTP/1.1', u'cmd_args': [],
u'web2py_path': u'/media/psf/Python/web2py', u'wsgi_url_scheme': u'https',
u'server_name': u'dev', u'remote_addr': u'172.16.100.173', u'is_jython':
False, u'applications_parent': u'/media/psf/Python/web2py', u'wsgi_version':
[1, 0], u'request_method': u'POST', u'web2py_original_uri':
u'/rpc_test/default/call/jsonrpc', u'server_port': u'8000',
u'http_content_type': u'application/json-rpc', u'http_accept_encoding':
u'gzip', u'wsgi_multithread': True, u'https': u'on', u'gluon_parent':
u'/media/psf/Python/web2py', u'server_software': u'Rocket 1.2.4',
u'web2py_version': u'Version 1.99.0 (2011-09-13 08:34:37)\n', u'http_host':
u'172.16.100.111:8000', u'wsgi_multiprocess': False, u'http_content_length':
u'57', u'request_uri': u'/rpc_test/default/call/jsonrpc', u'remote_port':
u'65141', u'app_folders': [u'/media/psf/Python/web2py/applications/admin/',
u'/media/psf/Python/web2py/applications/rpc_test/'], u'db_sessions': [],
u'query_string': '', u'wsgi_run_once': False, u'path_info':
u'/rpc_test/default/call/jsonrpc'}
{'content_length': '101', 'debugging': False, 'http_user_agent':
'xmlrpclib.py/1.0.1 (by www.pythonware.com)', 'http_content_length': '101',
'script_name': '', 'server_protocol': 'HTTP/1.1', 'cmd_args': [],
'web2py_path': '/media/psf/Python/web2py', 'wsgi_url_scheme': 'https',
'server_name': 'dev', 'remote_addr': '172.16.100.173', 'is_jython': False,
'applications_parent': '/media/psf/Python/web2py', 'wsgi_version': [1, 0],
'request_method': 'POST', 'web2py_original_uri':
'/rpc_test/default/call/xmlrpc', 'server_port': '8000', 'http_content_type':
'text/xml', 'http_accept_encoding': 'gzip', 'wsgi_multithread': True,
'https': 'on', 'gluon_parent': '/media/psf/Python/web2py',
'server_software': 'Rocket 1.2.4', 'web2py_version': 'Version 1.99.0
(2011-09-13 08:34:37)\n', 'http_host': '172.16.100.111:8000',
'wsgi_multiprocess': False, 'content_type': 'text/xml', 'request_uri':
'/rpc_test/default/call/xmlrpc', 'remote_port': '65143', 'app_folders':
['/media/psf/Python/web2py/applications/admin/',
'/media/psf/Python/web2py/applications/rpc_test/'], 'db_sessions': [],
'query_string': '', 'wsgi_run_once': False, 'path_info':
'/rpc_test/default/call/xmlrpc'}