upload file using post to https server

cerr ron.eggler at gmail.com
Thu Sep 23 14:10:55 EDT 2010


hi,
I've been unsucessfully trying to upload a file using POST to an https
server.
I've succesfully logged in and gotten to read something from the
server..
I have come up with something like this:
 authinfo = urllib2.HTTPBasicAuthHandler()
 authinfo.add_password(realm='Configuration Software',
 uri=url,
 user='admin',
 passwd='******')
 opener = urllib2.build_opener(authinfo)
 pagePtr = opener.open(url)
 dataRead = str(pagePtr.read())
 #Look for 'Software Upload' in the page
 if( "Software Upload" in dataRead ):
 print "FOUND Software Upload in string...<BR>"
 else:
 print "Software Upload page not found. Exiting..."
 sys.exit()
 values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' }
 try:
 data = urllib.urlencode( values )
 req = urllib2.Request( url, data )
 #response = urllib2.urlopen( req )
 response = opener.open( req )
 the_page = response.read()
 #print the_page
 except Exception,detail:
 print "err ",detail
 #Look for 'file must be efs' in the page
 if( "file must be efs" in the_page ):
 print "file must be efs. Exiting..."
 sys.exit()
 else:
 print "OK"
But the file doesn't seem to get there correctly. What I wanna do, is
mocking the upload from the html site with my python script.... the
html looks something like this:
<form method="post" action="/cgi-bin/config.pl" enctype="multipart/
form-data" onsubmit="return validateForm()" name="advance">
<input type="file" name="filename" tabindex="1" size="57" /
> <input type="submit" tabindex="2" name="submit"
value="Upload Image" /></form>
Thanks for your hints and suggestions on how I have to go about this!
Ron


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /