Client

Introduction

PyAMF isn’t just about the Adobe Flash Player talking to a Python backend, oh no. We have put together a client module which allows you to make AMF calls to an HTTP Gateway, whether that be PyAMF or other AMF implementations. If you come from a Adobe Flash background, this API will feel very natural to you.

Examples

The examples below are working, so feel free to try this out right now.

Basic Example

This example connects to a AMF gateway running at http://demo.pyamf.org/gateway/recordset and invokes the remote Python getLanguages method that is mapped to service.getLanguages. The result is printed on stdout.

1
2
3
4
5
6
from pyamf.remoting.client import RemotingService

client = RemotingService('http://demo.pyamf.org/gateway/recordset')
service = client.getService('service')

print service.getLanguages()

Authenication

Use setCredentials(username, password) to authenticate with an AMF client:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from pyamf.remoting.client import RemotingService

client = RemotingService('https://demo.pyamf.org/gateway/authentication')
client.setCredentials('jane', 'doe')

service = client.getService('calc')
print service.sum(85, 115) # should print 200.0

client.setCredentials('abc', 'def')
print service.sum(85, 115).description # should print Authentication Failed

Logging

Enable logging with a DEBUG level to log messages including the timestamp and level name.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from pyamf.remoting.client import RemotingService

import logging
logging.basicConfig(level=logging.DEBUG,
           format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s')

gateway = 'http://demo.pyamf.org/gateway/recordset'
client = RemotingService(gateway, logger=logging, debug=True)
service = client.getService('service')

print service.getLanguages()

HTTP Headers

You can modify the headers of the HTTP request using this convenient API:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import base64

from pyamf.remoting.client import RemotingService

gw = RemotingService('http://demo.pyamf.org/gateway/recordset')

gw.addHTTPHeader('Set-Cookie', 'sessionid=QT3cUmACNeKQo5oPeM0')
gw.removeHTTPHeader('Set-Cookie')

username = 'admin'
password = 'admin'
auth = base64.encodestring('%s:%s' % (username, password))[:-1]

gw.addHTTPHeader("Authorization", "Basic %s" % auth)

More

Check the API docs for more information. The source for the RecordSet example is also available.

Table Of Contents

Previous topic

General

Next topic

Shared Object

This Page