Codes from my life

proxy in xmlrpclib

This is just an extension of the example shown here http://docs.python.org/library/xmlrpclib.html#example-of-client-usage .

import xmlrpclib, httplib
class ProxiedTransport(xmlrpclib.Transport):
    def set_proxy(self, proxy):
        self.proxy = proxy
	self.puser_pass = puser_pass
    def make_connection(self, host):
        self.realhost = host
        h = httplib.HTTP(self.proxy)
        return h
    def send_request(self, connection, handler, request_body):
        connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
    def send_host(self, connection, host):
        connection.putheader('Host', self.realhost)
	connection.putheader('User-agent', self.user_agent)
	# Check is proxy username and password is set
	if len(self.puser_pass.strip()) != 0:
		connection.putheader('Proxy-authorization','Basic '+self.puser_pass)

p = ProxiedTransport()
proxyUsername = 'proxyuser'
proxyPassword = 'proxypass'
puser_pass = base64.encodestring('%s:%s' % (proxyUsername, proxyPassword)).strip()

p.set_proxy('proxy-server:8080', puser_pass)
server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p)
print server.currentTime.getCurrentTime()

A similar code has been used in my blog client GScribble.

Advertisements

Comments on: "proxy in xmlrpclib" (1)

  1. This is one awsome blog.4 thumbs up

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: