Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex

18.24xmlrpclib -- XML-RPC client access

New in version 2.2.

XML-RPC is a Remote Procedure Call method that uses XML passed viaHTTP as a transport. With it, a client can call methods withparameters on a remote server (the server is named by a URI) and get backstructured data. This module supports writing XML-RPC client code; ithandles all the details of translating between conformable Pythonobjects and XML on the wire.

class ServerProxy(uri[, transport[, encoding[, verbose[, allow_none[, use_datetime]]]]])
AServerProxy instance is an object that manages communicationwith a remote XML-RPC server. The required first argument is a URI(Uniform Resource Indicator), and will normally be the URL of theserver. The optional second argument is a transport factory instance;by default it is an internalSafeTransport instance for https:URLs and an internal HTTPTransport instance otherwise. Theoptional third argument is an encoding, by default UTF-8. The optionalfourth argument is a debugging flag. Ifallow_none is true, the Python constantNone will be translated into XML; thedefault behaviour is forNone to raise aTypeError.This is a commonly-used extension to the XML-RPC specification, but isn'tsupported by all clients and servers; seehttp://ontosys.com/xml-rpc/extensions.php for a description. Theuse_datetime flag can be used to cause date/time values to bepresented asdatetime.datetime objects; this is falseby default.datetime.datetime,datetime.date anddatetime.timeobjects may be passed to calls.datetime.date objectsare converted with a time of ``00:00:00''.datetime.time objects are converted using today's date.

Both the HTTP and HTTPS transports support the URL syntax extension forHTTP Basic Authentication:http://user:pass@host:port/path. Theuser:pass portion will be base64-encoded as an HTTP `Authorization'header, and sent to the remote server as part of the connection processwhen invoking an XML-RPC method. You only need to use this if theremote server requires a Basic Authentication user and password.

The returned instance is a proxy object with methods that can be usedto invoke corresponding RPC calls on the remote server. If the remoteserver supports the introspection API, the proxy can also be used to querythe remote server for the methods it supports (service discovery) andfetch other server-associated metadata.

ServerProxy instance methods take Python basic types and objects as arguments and return Python basic types and classes. Types that areconformable (e.g. that can be marshalled through XML), include thefollowing (and except where noted, they are unmarshalled as the samePython type):

NameMeaning
booleanTheTrue andFalse constants
integersPass in directly
floating-point numbersPass in directly
stringsPass in directly
arraysAny Python sequence type containing conformable elements. Arrays are returned as lists
structuresA Python dictionary. Keys must be strings, values may be any conformable type.
datesin seconds since the epoch (pass in an instance of theDateTime class) or adatetime.datetime,datetime.date ordatetime.time instance
binary datapass in an instance of theBinary wrapper class

This is the full set of data types supported by XML-RPC. Method callsmay also raise a specialFault instance, used to signalXML-RPC server errors, orProtocolError used to signal anerror in the HTTP/HTTPS transport layer. BothFault andProtocolError derive from a base class calledError. Note that even though starting with Python 2.2 youcan subclass builtin types, the xmlrpclib module currently does notmarshal instances of such subclasses.

When passing strings, characters special to XML such as "<",">", and "&" will be automatically escaped. However, it'sthe caller's responsibility to ensure that the string is free ofcharacters that aren't allowed in XML, such as the control characterswith ASCII values between 0 and 31 (except, of course, tab, newline andcarriage return); failing to do this will result inan XML-RPC request that isn't well-formed XML. If you have to passarbitrary strings via XML-RPC, use theBinary wrapper classdescribed below.

Server is retained as an alias forServerProxy for backwardscompatibility. New code should useServerProxy.

Changed in version 2.5:Theuse_datetime flag was added.

See Also:

XML-RPC HOWTO
A good description of XML operation and client software in several languages. Contains pretty much everything an XML-RPC client developer needs to know.
XML-RPC Hacks page
Extensions for various open-source libraries to support introspection and multicall.



Subsections


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp