How do I add basic authentication to a Python REST request?

I have the following simple Python code that makes a simple post request to a REST service -

params= { "param1" : param1,
          "param2" : param2,
          "param3" : param3 }
xmlResults = urllib.urlopen(MY_APP_PATH, urllib.urlencode(params)).read()
results = MyResponseParser.parse(xmlResults)

The problem is that the url used to call the REST service will now require basic authentication (username and password). How can I incorporate a username and password / basic authentication into this code, as simply as possible?

5
задан froadie 13 September 2010 в 19:25
поделиться