urllib2 - basic authentication and the put and delete methods

news.corp.adobe.com lafrance at adobe.com
Fri Jul 8 07:22:10 CEST 2005


I need to perform basic authentication and I also need to be able to use the 
put and delete methods to copy files / delete files on a server.

Here is how I successfully perform basic authentication to read a page:
------------------------------------------------
import urllib2, os, base64

os.system("cls")

theurl = 'http://myurl.com:9090/ESG/en_US/GLtest/'
username = 'myusername'
password = 'mypassword'

req = urllib2.Request(theurl)

realm = 'Apache Tomcat/4.1.27'

base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
authheader =  "Basic %s" % base64string
req.add_header("Authorization", authheader)

handle = urllib2.urlopen(req)

thepage = handle.read()

print thepage
------------------------------------------------

But despite much searching, I have yet to discover how to then use PUT and 
DELETE to copy files / delete files on the server.






More information about the Python-list mailing list