From 1ad87091c3fdbf4be7dec33fc31d3a2c767a8f35 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 12 Oct 2010 10:54:35 -0400 Subject: * We now have to disable site-packages because of LP: #659231 * Provide a better example of how to use basic auth in the rest api call --- src/mailman/rest/docs/basic.txt | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/mailman') diff --git a/src/mailman/rest/docs/basic.txt b/src/mailman/rest/docs/basic.txt index 177082c4a..614b074ba 100644 --- a/src/mailman/rest/docs/basic.txt +++ b/src/mailman/rest/docs/basic.txt @@ -44,13 +44,33 @@ Invalid credentials When you try to access the REST server using invalid credentials you will get an appropriate HTTP 401 Unauthorized error. - - >>> dump_json('http://localhost:8001/3.0/system', - ... username='baduser', password='badpass') - Traceback (most recent call last): - ... - HTTPError: HTTP Error 401: 401 Unauthorized - ... +:: + + >>> from base64 import b64encode + >>> auth = b64encode('baduser:badpass') + + >>> url = 'http://localhost:8001/3.0/system' + >>> headers = { + ... 'Content-Type': 'application/x-www-form-urlencode', + ... 'Authorization': 'Basic ' + auth, + ... } + + >>> from httplib2 import Http + >>> response, content = Http().request(url, 'GET', None, headers) + >>> print content + 401 Unauthorized + + User is not authorized for the REST API + + +But with the right headers, the request succeeds. + + >>> auth = b64encode('{0}:{1}'.format(config.webservice.admin_user, + ... config.webservice.admin_pass)) + >>> headers['Authorization'] = 'Basic ' + auth + >>> response, content = Http().request(url, 'GET', None, headers) + >>> print response.status + 200 .. _REST: http://en.wikipedia.org/wiki/REST -- cgit v1.2.3-70-g09d2