Indeed Massimo, that is the file.

Some comments:

   - I am forcing Content-Type to 'application/json-rpc' in WebClient.post
   - The data must be already json encoded
   - The opener.addheaders is still used, but since I am using 
   a urllib2.Request (to *really* force the Content-Type, which can not be 
   done with addheaders, as you can see in the previously linked StackOverflow 
   question), I would say the headers set with addheaders are not really 
   active.
   - That means self.detault_headers are probably not used
   - for jsonrpc post I have disabled form processing
   - and last but not least, my changes are based on 2.0.2. I assume no big 
   changes have been done for the WebClient since then, but I have not 
   verified.

I am not sure what are the implicactions of all these changes. Maybe some 
corrections are in order.

On Tuesday, December 18, 2012 4:27:26 AM UTC+1, Massimo Di Pierro wrote:
>
>  you point me to the file? Is it this one?
>
>
> https://github.com/gonvaled/web2py/blob/webclient_add_jsonrpc/gluon/contrib/webclient.py
>
>
> On Monday, 17 December 2012 14:01:18 UTC-6, Daniel Gonzalez wrote:
>>
>> I have slightly modified the WebClient to support jsonrpc. I am not sure 
>> everything is correctly covered, but it is suiting my needs.
>>
>> In case you are interested, you can see the changes here:
>>
>> https://github.com/gonvaled/web2py/tree/webclient_add_jsonrpc
>>
>> The biggest problem I had was 
>> that opener.addheaders.append((key,str(value))) is not working as (I) 
>> expected: the content-type is not rewritten:
>>
>> http://stackoverflow.com/questions/13920211/not-possible-to-set-content-type-to-application-json-using-urllib2
>>
>> On Monday, December 17, 2012 6:38:30 PM UTC+1, Daniel Gonzalez wrote:
>>>
>>> Hi,
>>>
>>> I am trying to understand how to use the included WebClient to test a 
>>> JSONRPC interface. One showstopper for me at the moment is that I see the 
>>> following in WebClient.post:
>>>
>>>                 # time the POST request
>>>                 data = urllib.urlencode(data)
>>>                 t0 = time.time()
>>>                 self.response = opener.open(self.url,data)
>>>                 self.time = time.time()-t0
>>>
>>> When doing JSONRPC accesses I do not want the data to be urlencoded. 
>>> Actually, I will prepare the data with json.dump, and I want WebClient to 
>>> POST it transparently (I guess this goes in the body of the POST request). 
>>> Is this at all possible? Is there an example of WebClient usage 
>>> for JSONRPC interfaces somewhere?
>>>
>>> Thanks,
>>> Daniel Gonzalez
>>>
>>

-- 



Reply via email to