Why is ClientCookie/urllib2 using https?

Grant Edwards grante at visi.com
Wed Sep 24 22:06:30 CEST 2003


In the program shown below, all of the connections to the
servers are using port 443 and https (TLS protocol) -- both the
initial connection to login.postini.com and subsequent
connections to user-3.postini.com.

It works, and I don't mind that it's encrypting the sessions as
well as the login, but I'd like understand why the connections
to "http://user-3.postini.com/exec/MsgCtr" are being done using
TLS to port 443 instead of raw TCP to port 80 as is implied by
the http: in the URL.

FWIW, it's a program to delete quarantined viruse-laden
messages from the server run by the Postini mail-filtering
service.  Viruses can only be deleted 10 at a time, and when
you've got 7000 of them, that's a hell of a lot of mouse
clicks.  When they're coming in 200-300 an hour, automating the
deleting process was the only reasonable solution.

---------------------------------8<---------------------------------
import re,sys
import ClientCookie
import urllib,urllib2

postData = urllib.urlencode({
'remember':'1',
'action':'login',
'email':sys.argv[1],
'pword':sys.argv[2]})

req1 = urllib2.Request("https://login.postini.com/exec/login",data=postData)
rsp1 = ClientCookie.urlopen(req1)

req2 = urllib2.Request("http://user-3.postini.com/exec/MsgCtr")
rsp2 = ClientCookie.urlopen(req2)

while 1:
    data = rsp2.read()
    
    m = re.search('<form name=virus .*</form>',data,re.M|re.S)
    if not m:
        print "no virus form found"
        sys.exit()
    vdata = m.group()

    m = re.search('Message 1 - [0-9]+ of [0-9]+',vdata,re.M|re.S)
    if not m:
        print "did not find message count"
        sys.exit()
    print m.group()
    
    r = re.compile('<input type="checkbox" name="msgid" value="([^"]*)">',re.M|re.S)
    m = r.findall(vdata)
    
    if not m:
        print "no virus msgids found"
        sys.exit()

    postData = urllib.urlencode({'submit':'Remove','disp':'M','action':'change_Msgs'})
    for msgid in m:
        postData += "&msgid="+msgid

    req2 = urllib2.Request("http://user-3.postini.com/exec/MsgCtr",postData)
    rsp2 = ClientCookie.urlopen(req2)

---------------------------------8<---------------------------------

-- 
Grant Edwards                   grante             Yow!  He is the
                                  at               MELBA-BEING... the ANGEL
                               visi.com            CAKE... XEROX him... XEROX
                                                   him --




More information about the Python-list mailing list