I just did this yesterday with the 'poster' module after fumbling around with various other ideas, which in the end just produced a lot of code and didn't get me very far. Poster makes this pretty easy, and if you can't install it to the system python path, use 'setup.py install --user' and it'll put it in your home directory under ~/.local. <div>

<br></div><div>With poster, it's a breeze. Here's what I've done. Hope it helps: </div><div><br></div><div><div>#!/usr/bin/env python</div><div>import random</div><div>from poster.encode import multipart_encode</div>

<div>from poster.streaminghttp import register_openers</div><div>import urllib2</div><div>import threading</div><div>import time</div><div><br></div><div>class Requestor(threading.Thread):</div><div>    def __init__(self, port):</div>

<div>        threading.Thread.__init__(self)</div><div>        self.port = port</div><div><br></div><div>    def run(self):</div><div>        register_openers()</div><div>        post_param1 = 'cheddar'</div><div>

        post_param2 = 'leicester'</div><div><br></div><div>        params, headers = multipart_encode({"pic": open("image.jpg"), "param1": post_param1, "param2": post_param2})</div>

<div><br></div><div>        request = urllib2.Request("http://mybox:%s/" % self.port, params, headers)</div><div><br></div><div>        curtime = time.time()</div><div>        response = urllib2.urlopen(request).read()</div>

<div>        perftime = time.time() - curtime</div><div><br></div><div>        print "Query time: %s\n" % perftime</div><div><br></div><div>if __name__ == "__main__":</div><div>    for i in range(2000):</div>

<div>        port = random.choice(range(8885,8905))</div><div>        t = Requestor(port)</div><div>        t.start()</div><div><br></div><div>This is a basic threaded performance testing script that sends an image, and two other paramters, all in a POST request to a web server that opens multiple ports. If you don't need the threading, you should be able to rip the 'run()' method out of the class and just run it by itself (save an edit or two -- like hard-coding or otherwise replacing self.port). </div>

<div><br></div><div>Good luck! </div><div>brian</div><div><br><div class="gmail_quote">On Fri, Sep 24, 2010 at 4:23 AM, Dennis Lee Bieber <span dir="ltr"><<a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">On Thu, 23 Sep 2010 11:10:55 -0700 (PDT), cerr <<a href="mailto:ron.eggler@gmail.com">ron.eggler@gmail.com</a>><br>


declaimed the following in gmane.comp.python.general:<br>
<div class="im"><br>
<br>
>         values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' }<br>
><br>
>         try:<br>
>                 data = urllib.urlencode( values )<br>
<br>
</div><div class="im">> But the file doesn't seem to get there correctly. What I wanna do, is<br>
> mocking the upload from the html site with my python script.... the<br>
> html looks something like this:<br>
<br>
</div>        And are you expecting the server to somehow crawl down the socket to<br>
your machine to find the file, then suck it up?<br>
<br>
        Where do you actually attach the file data to the outgoing response?<br>
<br>
        Suggest you reference the RFC that added file upload to HTML:<br>
<a href="http://www.faqs.org/rfcs/rfc1867.html" target="_blank">http://www.faqs.org/rfcs/rfc1867.html</a><br>
<br>
        In particular, section 3.3<br>
-=-=-=-=-=-<br>
3.3 use of multipart/form-data<br>
<br>
   The definition of multipart/form-data is included in section 7.  A<br>
   boundary is selected that does not occur in any of the data. (This<br>
   selection is sometimes done probabilisticly.) Each field of the form<br>
   is sent, in the order in which it occurs in the form, as a part of<br>
   the multipart stream.  Each part identifies the INPUT name within the<br>
   original HTML form. Each part should be labelled with an appropriate<br>
   content-type if the media type is known (e.g., inferred from the file<br>
   extension or operating system typing information) or as<br>
   application/octet-stream.<br>
-=-=-=-=-=-<br>
<br>
        You've just supplied the file NAME part of the form, but not the<br>
file data.<br>
<font color="#888888">--<br>
        Wulfraed                 Dennis Lee Bieber         AF6VN<br>
        <a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a>    <a href="HTTP://wlfraed.home.netcom.com/" target="_blank">HTTP://wlfraed.home.netcom.com/</a><br>
</font><div><div></div><div class="h5"><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Brian K. Jones<br>My Blog          <a href="http://www.protocolostomy.com">http://www.protocolostomy.com</a><br>Follow me      <a href="http://twitter.com/bkjones">http://twitter.com/bkjones</a><br>


</div></div>