Showing posts with label pyamf. Show all posts
Showing posts with label pyamf. Show all posts

Tuesday, September 8, 2009

Putting available ports to use with AMF

In a previous post, see a detailed a procedure to choose and make available a tcp/alt port on a web server to avail the use of asynchronous data services. That post leads to this one, in which AMF calls are made over the available port.

To start, here is a method to test the port for an http response using netcat, via stearns.org:
echo -e "GET http://yoursite.com HTTP/1.0\n\n" | nc yoursite.com 80 | less
...or using the alternate available port...
echo -e "GET http://yoursite.com HTTP/1.0\n\n" | nc yoursite.com 8080 | less
This is a good example of using netcat as a client to get a response from an http service.

Analogous to this is the stated goal of this post, establishing connectivity between a lightweight client and an AMF service. Does that service by definition reside on an HTTP gateway? What type of gateway is the service? That remains to be answered.

For now, note that there is a starting example available from pyamf.com that allows you to test a connection to a third-party HTTP gateway. Titled PyAMF AMF Client, it works in the following manner to establish a simple methodology.
  1. In SSH, launch a python command line
  2. Load the modules in pyamf to initiate a test
  3. Request the remote service and look for a successful response
Here, copied from the pyamf.com example, is the applicable sequence
from pyamf.remoting.client import RemotingService

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

print service.getLanguages()
...which should directly result in the following response from pyamf.com
<pyamf.amf0.recordset><pyamf.amf0.recordset></pyamf.amf0.recordset></pyamf.amf0.recordset>
Why does this work as it should? Some of the reasons why it works

pyamf.remoting.client.RemotingService (see API)


We instantiated the class RemotingService, the instance call of which includes a parametric reference to an available gateway. Once you provide a valid gateway address, you have established a client for AMF calls.


getService method


The method parameter is the name of a service, in this case the service defined at http://demo.pyamf.org/gateway/recordset/. Try browsing to this address and you will see


400 Bad Request

To access this PyAMF gateway you must use POST requests (GET received)

The gateway provides information that it is a PyAMF gateway and only accepts POST requests. If you use netcat to contact the gateway...


echo -e "GET http://demo.pyamf.org/gateway/recordset HTTP/1.0\n\n" | nc demo.pyamf.org 80 | less

...you will get a similar response. If you netcat a POST to the gateway, you will get this...

HTTP/1.1 500 Internal Server Error
Date: Wed, 09 Sep 2009 15:21:18 GMT
Server: Apache/2.0.55 (Ubuntu) DAV/2 SVN/1.5.6 mod_python/3.3.1 Python/2.5.4 mod_wsgi/2.4 PHP/5.1.2 mod_ssl/2.0.55 OpenSSL/0.9.8a mod_perl/2.0.2 Perl/v5.8.7
Content-Length: 534
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
info@pyamf.org and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>

This is a longer response, but not a successful response. The question remains, how can a request to the server result in a service initiation? Let's look at some other possibilities.

Tuesday, August 25, 2009

Setting up PyAMF for Django on Slicehost VPS

I'm continuing to elaborate on a server environment for multiple django projects. In this case, they are serving flex applications on the front end and providing AMF data through PyAMF.

The structure allows domains to be added as needed in a /domains/ subdirectory. Each directory has a virtualenv set to encapsulate the packages installed and minimize complications.

Currently, I am installing PyAMF onto my current project dir using easy_install, from /domains/site.com/site.com/bin

./easy_install pyamf

it is important to run the command from within your virtual environment, otherwise it will default to your system install at /usr/lib/python2.5/site-packages, which isn't mapped to a server and won't be using pyamf at all.

Install PyAMF 0.42 successful. "So far so what," you say pithily. Well, it could certainly be worse than that. Remember that easy_install allows indiscriminate updating of installs via the command

./easy_install -U pyamf

Next some info about eclipse and subversive.