The Objective: A script which cycles through a list of proxies and sends a post request, containing a file to a PHP page on my server, which then calculates delivery time. It's a pretty useless script, but I am using it to teach myself about urllib2.
The Problem: So far I have got multipart/form-data sending correctly using Poster, but I can't get it to send through a proxy, let alone a cycling list of proxies. I have tried using an OpenerDirector with urllib2.ProxyHandler
, but I believe Poster
defines it's own opener to perform it's magic.
Below is the code to send a multipart/form-data request with poster.
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
fields = {"type": "image",
"fileup": open("/home/chaz/pictures/test.jpg", "rb")
}
register_openers() #I believe this is the key
datagen, headers = multipart_encode(fields)
request = urllib2.Request("http://foo.net", datagen, headers)
lastResponse = urllib2.urlopen(request).read()
Any help would be much appreciated as I am stumped.