upload file using post to https server

C

cerr

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" /
&nbsp;&nbsp;<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
 
D

Dennis Lee Bieber

values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' }

try:
data = urllib.urlencode( values )
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:

And are you expecting the server to somehow crawl down the socket to
your machine to find the file, then suck it up?

Where do you actually attach the file data to the outgoing response?

Suggest you reference the RFC that added file upload to HTML:
http://www.faqs.org/rfcs/rfc1867.html

In particular, section 3.3
-=-=-=-=-=-
3.3 use of multipart/form-data

The definition of multipart/form-data is included in section 7. A
boundary is selected that does not occur in any of the data. (This
selection is sometimes done probabilisticly.) Each field of the form
is sent, in the order in which it occurs in the form, as a part of
the multipart stream. Each part identifies the INPUT name within the
original HTML form. Each part should be labelled with an appropriate
content-type if the media type is known (e.g., inferred from the file
extension or operating system typing information) or as
application/octet-stream.
-=-=-=-=-=-

You've just supplied the file NAME part of the form, but not the
file data.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top