2011-01-07 4 views

ответ

10

Вы можете подкласса 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 
+0

Я не могу использовать это как я получаю исключение аф первый вызов метода, см http://stackoverflow.com/questions/17569519/unable-to-use-custom-transport-class- с-питон-XMLRPCLIB-из-за-на-TypeError-УНБ – sorin

 Смежные вопросы

  • Нет связанных вопросов^_^