Hello everybody (first post here).
I am trying to send data to a webpage. This webpage request two fields (a file and an e-mail address) if everything is ok the webpage returns a page saying "everything is ok" and sends a file to the provided e-mail address. I execute the code below and I get nothing in my e-mail account.
import urllib, urllib2
params = urllib.urlencode({'uploaded': open('file'),'email': 'user@domain.com'})
req = urllib2.urlopen('http://webpage.com', params)
print req.read()
the print command gives me the code of the home page (I assume instead it should give the code of the "everything is ok" page).
I think (based o google search) the poster module should do the trick but I need to keep dependencies to a minimum, hence I would like a solution using standard libraries (if that is possible).
Thanks in advance.
Try this: Using MultipartPostHandler to POST form-data with Python
Thanks everybody for your answers. I solve my problem using the mechanize library.
This site could checks Referer, User-Agent and Cookies.
Way to handle all of this is using
urllib2.OpenerDirector
which you can get byurllib2.build_opener
.Then prepare parameters with
urlencode
and send request byopener.open(params)
Documentation for Python 2.7: cookielib, OpenerDirector