0

I am using the following code to login to facebook .

import http.cookiejar
import urllib


url = 'https://www.facebook.com/login.php'
values = {'email' : 'john@example.com',
      'pass' : 'mypassword' }

data = urllib.parse.urlencode(values)
cookies =  http.cookiejar.CookieJar()

opener = urllib.request.build_opener(
urllib.request.HTTPRedirectHandler(),
urllib.request.HTTPHandler(debuglevel=0),
urllib.request.HTTPSHandler(debuglevel=0),
urllib.request.HTTPCookieProcessor(cookies))

binary_data = data.encode('ascii')
response = opener.open(url, binary_data)
the_page = response.read()
http_headers = response.info()

But when I am behind a corporate Proxy firewall , The request always time out . Can You please get me a solution to authenticate through the proxy so that the request reached the remote facebook server .

Shuhail Kadavath
  • 448
  • 3
  • 13
  • http://stackoverflow.com/questions/11763028/python-3-urllib-http-error-407-proxy-authentication-required – Klaus Jul 09 '13 at 12:55

1 Answers1

0

Add a proxy handler:

opener = urllib.request.build_opener(
    urllib.request.ProxyHandler({'http': r'http://username:password@url:port'}),
    urllib.request.HTTPRedirectHandler(),
    urllib.request.HTTPHandler(debuglevel=0),
    urllib.request.HTTPSHandler(debuglevel=0),
    urllib.request.HTTPCookieProcessor(cookies)
)
ElmoVanKielmo
  • 10,907
  • 2
  • 32
  • 46