urllib2 - basic authentication and the put and delete methods

  • Thread starter news.corp.adobe.com
  • Start date
N

news.corp.adobe.com

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
 
D

deelan

news.corp.adobe.com wrote:
(...)
But despite much searching, I have yet to discover how to then use PUT and
DELETE to copy files / delete files on the server.

i believe you have to use httplib for that:
<http://docs.python.org/lib/module-httplib.html>

examples here:
<http://docs.python.org/lib/httplib-examples.html>

basically you pass auth headers whie
using PUT/DELETE verbs:

## untested! ##

headers = {
"Authorization": authheader # your base 64 str
}
conn.request("PUT", "/your/url/here", body, headers)

HTH,
deelan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top