Use python to connect to a php page and upload image
Question: I would like to know if its possible to use python to connect to a certain
site

(EX: <http://www.example.com/python> )

and upload an image from the computer. Basically I have a python script that
takes images from the webcam. Now after it takes the image how can i send that
image to a webpage. If you tell me how to get it to connect to the page I can
handle the rest. Thanks in advance!

THIS IS THE PYTHON SCRIPT AT HAND:

    
    
    from VideoCapture import Device
    
    cam = Device(devnum=1)
    cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1)
    


Answer: Use `urllib2` for this. Basically build up a
[`urllib2.Request`](http://docs.python.org/library/urllib2.html#urllib2.Request)
with the URL to the PHP script, and then `add_data` to add the image data that
you want to submit.

**edit** : you can follow the examples
[here](http://www.doughellmann.com/PyMOTW/urllib2/), and specifically [this
example](http://www.doughellmann.com/PyMOTW/urllib2/#posting-form-data) to
help understand the full process

