Python - POSTing with a urllib2 opener

python, urllib2

Solution

This is such a silly question once one realizes the answer.

Just use:

open(URL,data)

for the first part, and like Rachel Sanders mentioned,

geturl()

for the second part.

I really can't figure out how the whole Request/opener thing works though; I couldn't find any nice documentation :/

Problem

I have a urllib2 opener, and wish to use it for a POST request with some data. I am looking to receive the content of the page that I am POSTing to, and also the URL of the page that is returned (I think this is just a 30x code; so something along those lines would be awesome!). Think of this as the code: ``` anOpener = urllib2.build_opener(???,???) anOpener.addheaders = [(???,???),(???,???),...,(???,???)] # do some other stuff with the opener data = urllib.urlencode(dictionaryWithPostValues) pageContent = anOpener.THE_ANSWER_TO_THIS_QUESTION pageURL = anOpener.THE_SECOND_PART_OF_THIS_QUESTION ```

Original source