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.
How to send custom http_headers for RPC calls using python xmlrpclib?
Asked Answered
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
I am not able to use this as I am getting an exception af the first method call, see #17570019 –
Predatory
© 2022 - 2024 — McMap. All rights reserved.