Mimicing an HTML form

Zach Hobesh hobesh at gmail.com
Wed Aug 12 18:30:48 CEST 2009

Hi all,
I'm having alot of trouble automating the submitting of form.  I have an
HTML page that works and it looks like this:

<form action='*script here*' enctype="multipart/form-data" method="post">
<input name="txtTitle" id="txtTitle" value="Video Title" maxlength="50"
/><BR />
<input type="file" id="FileUploadedVideo" name="FileUploadedVideo" /><BR />
<input name="txtDescription" id="txtDescription" value="Description"
maxlength="50" /><BR />
<input id="hdnADCID" name="hdnADCID" value="*app ID here*" type="hidden" />
<input type="submit" value="Submit" />

When I put valid values for the handling script an app ID, this page works.
 Now I'm trying to turn this same functionality into a script.  Here's my

import urllib
import os
import urllib2

appID = *value here*
video = os.path.normpath(os.getcwd() + '/news.wmv')
title = 'News'
desc = 'Here is a sample News video'

uploader = *script here*

print "Encoding url..."
data = urllib.urlencode({"FileUploadedVideo": video,
                         "hdnADCID" : appID,
                         "txtTitle" : title,
                         "txtDescription": desc})

user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }

print "Calling url..."
req = urllib2.Request(uploader, data, headers)

response = urllib2.urlopen(req)
s = response.read()

print "Writing results..."
result = open('result.html','w')

Does anybody have any suggestions?  I keep on getting bad request, so I'm
assuming that the html page is passing something that my script is not.  Is
there some way to scrape the POST request from the html form?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090812/b1d412b0/attachment.html>

More information about the Python-list mailing list