[Baypiggies] Any advice using HTTP REST in a Python client

Douglas Sims doug at apley.com
Sun Jan 6 02:32:02 CET 2008


Hi Robert

You might try the urllib2 library: http://docs.python.org/lib/module-urllib2.html

This library supports http, https, ftp, cookies, basic authentication,  
put, post, head, etc.

Here is a quick example showing how you might use this.  This is a  
short program which downloads a copy of the FAA aircraft registration  
database from the web.  The database is in the form of a zipped file  
on the FAA web site.  This program doesn't do any error trapping as  
you might want to, but it's been quietly plugging away since May (run  
by a cron job) and never had any errors to trap.

Good luck!


Douglas Sims
Doug at Apley.com



#!/usr/bin/python
# Doug at Apley.com 2007-05-23

import urllib2, os, time

# refer to http://www.faa.gov/licenses_certificates/aircraft_certification/aircraft_registry/releasable_aircraft_download/

# The URL contains the current year and month value.  Strangely, you  
can't retrieve older copies of the file just by using older year/month  
values.
# Also, the file is replaced several times a month and still lives at  
the same URL.
aircraft_registration_url=time.strftime('http://registry.faa.gov/database/AR 
%m%Y.zip')

local_aircraft_registration_archive=time.strftime('/var/ 
aircraft_registrations/%Y')
if not os.path.isdir(local_aircraft_registration_archive):
	os.mkdir(local_aircraft_registration_archive)

f = urllib2.urlopen(aircraft_registration_url)
aircraft_registrations = f.read()
f.close()

fout=file(local_aircraft_registration_archive+'/'+time.strftime('%Y-%m- 
%d_%H_%M_%S'), 'wb')
fout.write(aircraft_registrations)
fout.close





On Jan 5, 2008, at 5:38 PM, Robert Field wrote:

> Hi, All --
>
> I have a need to be able to upload and download files from a server  
> using
> a REST interface. The download would be by GET, the upload by PUT, I'm
> expecting.
>
> I'm not making too much headway on this and was wondering if anyone  
> had
> experience or knew of a tutorial resource.
>
> Thanks,
> Robert
>
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies



More information about the Baypiggies mailing list