views:

3647

answers:

4
+2  A: 

If you're using Python 2.5 or newer, urllib2_file is both unnecessary and unsupported, so check which version you're using (and perhaps upgrade).

If you're using Python 2.3 or 2.4 (the only versions supported by urllib2_file), try running the sample code and see if you have the same problem. If so, there is likely something wrong either with your Python or urllib2_file installation.

EDIT:

Also, you don't seem to be using either of urllib2_file's two supported formats for POST data. Try using one of the following two lines instead:

d = ['uploaded', open(sys.argv[1:])]
## --OR-- ##
d = {'uploaded': open(sys.argv[1:])}
Ben Blank
You say that urllib2_file is unnecessary on python 2.5 and greater, but this functionality doesn't exist in python yet. Based on http://bugs.python.org/issue3244, multipart/form-data uploads may be here in 2.7, but that's not released yet.
archbishop
I haven't looked at the problem since I posted this more than a year ago, but at the time, I was able to duplicate urllib2_file's functionality in Python 2.6 and even the library's page says it is only needed for Python 2.3 and 2.4. I can only assume that bug refers to some separate (but probably closely related) issue. :-)
Ben Blank
A: 

First, there's a third way to run Python programs.

From cmd.exe, type python myprogram.py. You get a nice log. You don't have to type stuff one line at a time.

Second, check the urrlib2 documentation. You'll need to look at urllib, also.

A Request requires a URL and a urlencoded encoded buffer of data.

data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format.

You need to encode your data.

S.Lott
A: 

I've updated the first question. I've got it to work in command line but when I'm trying to use it in the Send To folder through a shortcut it just doesn't work.

No one has any ideas? :(

Salty
Its not a problem with the spaces in the filename is it? Sometimes python gets confused with them
Andrew Cox
Nope, there are no spaces in the filename. Like I mentioned, it works perfectly in the command line, so I'm not sure if the code is the problem here.
Salty
If its not related to the code, maybe you get better answers by posting another question?Also, if you want to update your question, edit (button at top of page) the question rather than providing an answer for it. :)
mizipzor
A: 

If you're still on Python2.5, what worked for me was to download the code here:

http://peerit.blogspot.com/2007/07/multipartposthandler-doesnt-work-for.html

and save it as MultipartPostHandler.py

then use:

import urllib2, MultipartPostHandler

opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler())
opener.open(url, {"file":open(...)})

or if you need cookies:

import urllib2, MultipartPostHandler, cookielib

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj), MultipartPostHandler.MultipartPostHandler())
opener.open(url, {"file":open(...)})
abjennings