title: Python urllib2 file upload problems
body: <p>I'm currently trying to initiate a file upload with urllib2 and the <a href="http://fabien.seisen.org/python/urllib2_multipart.html" rel="nofollow noreferrer">urllib2_file</a> library. Here's my code:</p>
  
  <pre><code>import sys
  import urllib2_file
  import urllib2
  
  URL='http://aquate.us/upload.php'
  d = [('uploaded', open(sys.argv[1:]))]
  req = urllib2.Request(URL, d)
  u = urllib2.urlopen(req)
  print u.read()
  </code></pre>
  
  <p>I've placed this .py file in my My Documents directory and placed a shortcut to it in my Send To folder (the shortcut URL is  ).</p>
  
  <p>When I right click a file, choose Send To, and select Aquate (my python), it opens a command prompt for a split second and then closes it. Nothing gets uploaded.</p>
  
  <p>I knew there was probably an error going on so I typed the code into CL python, line by line.
  When I ran the <code>u=urllib2.urlopen(req)</code> line, I didn't get an error; 
  <a href="http://www.aquate.us/u/55245858877937182052.jpg" rel="nofollow noreferrer">alt text http://www.aquate.us/u/55245858877937182052.jpg</a></p>
  
  <p>instead, the cursor simply started blinking on a new line beneath that line. I waited a couple of minutes to see if something would happen but it just stayed like that. To get it to stop, I had to press ctrl+break.</p>
  
  <p>What's up with this script?</p>
  
  <p>Thanks in advance!</p>
  
  <p>[Edit]
  Forgot to mention -- when I ran the script without the request data (the file) it ran like a charm. Is it a problem with urllib2_file?</p>
  
  <p>[edit 2]:</p>
  
  <pre><code>import MultipartPostHandler, urllib2, cookielib,sys
  import win32clipboard as w
  cookies = cookielib.CookieJar()
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies),MultipartPostHandler.MultipartPostHandler)
  params = {"uploaded" : open("c:/cfoot.js") }
  a=opener.open("http://www.aquate.us/upload.php", params)
  text = a.read()
  w.OpenClipboard()
  w.EmptyClipboard()
  w.SetClipboardText(text)
  w.CloseClipboard()
  </code></pre>
  
  <p>That code works like a charm if you run it through the command line.</p>