opening websites using urllib2 from behind corporate firewall - 11004 getaddrinfo failed

前端 未结 2 1468
失恋的感觉
失恋的感觉 2020-11-30 11:40

I am trying to access a website from behind corporate firewall using below:-

password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_passw         


        
相关标签:
2条回答
  • 2020-11-30 12:34

    On Windows, I observed that python uses the IE Internet Options-> LAN Settings settings. So even if we use urllib2 to install opener and specify the proxy_url, it would continue to use the IE settings.

    It worked fine finally, when I exported a system variable:

    http_proxy=http://userid:pswd@proxyurl.com:port
    
    0 讨论(0)
  • 2020-11-30 12:39

    If you are using Proxy and that proxy has Username and Password (which many corporate proxies have), you need to set the proxy handler with urllib2.

      proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' + proxy_ip
      proxy_support = urllib2.ProxyHandler({"http":proxy_url})
      opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
      urllib2.install_opener(opener)
    

    HTTPBasicAuthHandler is used to provide credentials for the site which you are going to access and not for going through the proxy. The above snippet might help you.

    0 讨论(0)
提交回复
热议问题