ServiceProxy

28 views
Skip to first unread message

Hannes Koller

unread,
Feb 29, 2012, 4:31:17 AM2/29/12
to json...@googlegroups.com

Hi,

I ran into a problem with the ServiceProxy class yesterday.  I was trying to connect to a Service but all I got were errors of the kind "415 Unsupported Media Type". After some poking around I found out that the ServiceProxy does not set the "Content-Type" header of the request. I wrote a small patch to remedy the problem and thought maybe this could be of interest so here it goes:

<code>

import urllib2  # I had to use urllib2 instead of urllib  (http headers)


class ServiceProxy(object):

def __call__(self, *args):

  postdata = dumps({"method": self.__serviceName, 'params': args, 'id':'jsonrpc'})

 

  #

  # BEGIN patch


  req = urllib2.Request(url=self.__serviceURL, data=postdata)

  req.add_header("Content-Type", "application/json")

  respdata = urllib2.urlopen(req).read()


  # END patch

  #


  resp = loads(respdata)

  .....


</code>


Cheers,
Hannes :)

Reply all
Reply to author
Forward
0 new messages