如何使用python xmlrpclib为RPC调用发送自定义http_头?

如何使用python xmlrpclib为RPC调用发送自定义http_头?,python,http-headers,xml-rpc,xmlrpclib,Python,Http Headers,Xml Rpc,Xmlrpclib,如何使用pythonxmlrpclib库发送自定义的HTTP头文件? 在调用RPC方法时,我需要发送一些特殊的自定义http\u头。您可以将xmlrpclib.Transport子类化,并将其作为参数传递给ServerProxy。选择一个要覆盖的方法(我选择了send_content),您就可以设置了 # simple test program (from the XML-RPC specification) from xmlrpclib import ServerProxy, Transpor

如何使用python
xmlrpclib
库发送自定义的
HTTP头文件?

在调用
RPC
方法时,我需要发送一些特殊的自定义
http\u头

您可以将
xmlrpclib.Transport
子类化,并将其作为参数传递给
ServerProxy
。选择一个要覆盖的方法(我选择了
send_content
),您就可以设置了

# 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

我无法使用它,因为我在第一次方法调用时遇到异常,请参阅