My objective is to log onto a wiki account (specifically wikipedia) using the http proxies provided by them (145.97.39.130 - 145.97.39.140:8 0). The operating system is Windows XP/Windows Server 2003. Or more conveniently, what do I need to change in the standard python library so that all python>>interne t interaction would be done through a proxy? (I'm guessing urlib2.py?)
I have a program login.py (full script: http://deadbeefbabe.org/paste/490, specifically this section: http://deadbeefbabe.org/paste/489):
pagename = self.site.login _address()
if self.site.hostn ame() in config.authenti cate.keys():
response = urllib2.urlopen (urllib2.Reques t('http://'+self.site.hos tname()+pagenam e, data))
data = response.read()
wikipedia.cj.sa ve(wikipedia.CO OKIEFILE)
return "Ok"
else:
conn = httplib.HTTPCon nection("145.97 .39.134:80")
conn.request("P OST",'http://'+self.site.hos tname()+pagenam e, data, headers)
response = conn.getrespons e()
conn.close()
This allows the user to log onto a wiki account with the proxy 145.97.39.134:8 0. However this is only done under the else clause, so as soon as the user is connected onto the account, the user goes back to using their normal internet connection settings. My question is, how would I do the same thing for the if clause, so that data = response.read() would connect to the wiki site using the http proxy 145.97.39.134:8 0? Do I need to make changes in the login.py program, or perhaps in the standard Python library urllib2.py itself? I read some, and I thought that maybe urllib2.urlopen (urllib2.Reques t('http://'+self.site.hos tname()+pagenam e, data, 145.97.39.134:8 0)) would help? Someone else gave me this code: os.environ['http_proxy'] = 'http://localhost:8050' but I have no idea where to place it. Well, any help would be greatly appreciated! :)
-Alimah