How can I send custom HTTP Headers
using python xmlrpclib
library ! ?
I need to send some special custom http_headers
at the time of calling RPC
methods.
You can subclass xmlrpclib.Transport
and pass that as an argument to ServerProxy
. Pick a method to override (I chose send_content
) and you're set.
# simple test program (from the XML-RPC specification)
from xmlrpclib import ServerProxy, Transport, Error
class SpecialTransport(Transport):
def send_content(self, connection, request_body):
print "Add your headers here!"
connection.putheader("Content-Type", "text/xml")
connection.putheader("Content-Length", str(len(request_body)))
connection.endheaders()
if request_body:
connection.send(request_body)
# server = ServerProxy("http://localhost:8000") # local server
server = ServerProxy("http://betty.userland.com", transport=SpecialTransport())
print server
try:
print server.examples.getStateName(41)
except Error, v:
print "ERROR", v
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With