My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Using_Connection  
Using the Connection Class
Featured
Updated Feb 4, 2010 by bost...@gmail.com

Introduction

Basic usage patterns for the Connection wrapper.

Details

Usage

from restful_lib import Connection

# Should also work with https protocols
base_url = "http://ora.ouls.ox.ac.uk:8080/fedora"

conn = Connection(base_url, username="fedoraAdmin", password="blahblah")

Examples

1- A DELETE request on http://example.org/items/11232344

conn = Connection("http://example.org", username="XXX", password="XXX")

conn.request_delete('/items/11232344')

2- A GET request to /search, with parameter q = "Test", and request header "Accept: text/json"

conn.request_get("/search", args={'q':'Test'}, headers={'Accept':'text/json'})

3- A HEAD request on "/item" (using the full request method, rather than one of the convenience ones) - it is not recommended to use the direct method when using the GAE_Connection class, due to method names being remapped to integers by urlfetch. Use request_head instead.

conn.request("/item", method="HEAD")

Method Responses

All the methods respond with a dictionary with two parts: a dictionary of the response headers (status, etc) and a text item, with key 'body'.

E.g.

>>> conn.request_post("/upload", body=body) {u'body': u'', u'headers': {'status': '204', 'content-length': '0', 'server': 'Bigfoot/11.572.26883', 'connection': 'close', 'cache-control': 'max-age=7200, must-revalidate', 'date': 'Wed, 14 May 2008 16:09:18 GMT', 'content-type': 'text/plain; charset=UTF-8'}}

Comment by fractalb...@gmail.com, Apr 1, 2010

When calling the conn.request_post method, it is helpful to know that the "body" can be a string of the format like the following:

conn = Connection('https://my.url.com') conn.request_post('/api/myendpoint', body='parm1=p1&parm2=p2&parm3=p3&parm4=p4')

Comment by achim.he...@gmail.com, Nov 25, 2011

When you get a an error complaining that a float was expected, upgrade your httplib2 (e.g. to {{httplib2==0.7.2}}). When you get SSL errors with a self-signed (or other non-universally-known) certificate, add your CA to {{site-packages/httplib2/cacerts.txt}}.


Sign in to add a comment
Powered by Google Project Hosting