Extend urllib2 to support HTTP POST file upload
Python PHP
Switch branches/tags
Nothing to show
Clone or download
seisen Added upload.html/upload.php on examples/
Added unit testing in tests/
Added upload.html/upload.php on examples/
Unit tests works on python 2.3 / 2.4 / 2.5
Updated test-upload.py
You can now change form_name and/or filename on post_data structure (see README)
Change license from GPL to Python Software Foundation License v2
Latest commit cf4c4c8 Apr 24, 2010


Python urllib2_file.py enable you to upload files using HTTP multipart/form-data


python setup.py test
python setup.py build
python setup.py install


import urllib2_files
import urllib2

data = { 'foo':         'bar',
         'form_name':    open("/lib/libc.so.1") }

(send something like: 'Content-Disposition: form-data; name="form_name"; filename="form_name";' )

Or if you want to specify a different filename:

data = {'foo':         'bar',
        'form_name':   {'fd':       open('/lib/libresolv.so.2',
                        'filename': 'libresolv.so'} }

(send something like: 'Content-Disposition: form-data; name="form_name"; filename="libresolv.so";' )

u = urllib2.urlopen('http://site.com/path/upload.php', data)

Tested with:
 python 2.3
 python 2.4
 python 2.5