Python Proxy Error With Requests Library

前端 未结 3 2080
我寻月下人不归
我寻月下人不归 2020-12-31 17:52

I am trying to access the web via a proxy server in Python. I am using the requests library and I am having an issue with authenticating my proxy as the proxy I am using req

相关标签:
3条回答
  • 2020-12-31 18:26

    You should remove the embedded username and password from proxyDict, and use the auth parameter instead.

    import requests
    from requests.auth import HTTPProxyAuth
    
    proxyDict = { 
              'http'  : '77.75.105.165', 
              'https' : '77.75.105.165'
            }
    auth = HTTPProxyAuth('username', 'mypassword')
    
    r = requests.get("http://www.google.com", proxies=proxyDict, auth=auth)
    
    0 讨论(0)
  • 2020-12-31 18:37

    I've been having a similar problem on Windows and found the only way to get requests to work was to set the proxies as environment variables before I started Python. For you this would be something like this:

    set HTTP_PROXY=http://77.75.105.165
    set HTTPS_PROXY=https://77.75.105.165
    

    You might also want to check is there's a specific port required, and if so set it after the url. For example, if the port is 8443 then do:

    set HTTP_PROXY=http://77.75.105.165:8443
    set HTTPS_PROXY=https://77.75.105.165:8443
    
    0 讨论(0)
  • 2020-12-31 18:45

    You can use urllib library for this.

    from urllib import request
    request.urlopen("your URL", proxies=request.getproxies())
    
    0 讨论(0)
提交回复
热议问题