简体   繁体   中英

python requests module proxy handler not working

I am using python request module for doing HTTP communications. I was using proxy before doing any communication.

import requests

proxy = {'http': 'xxx.xxx.xxx.xxx:port'}

                   OR

proxy = {'http': 'http://xxx.xxx.xxx.xxx:port'}

                  OR

proxy = {'http://xxx.xxx.xxx.xxx:port'}


requests.get(url, proxies = proxy)

I am using the above code to add the proxy to the request object. But its seems like proxy is not working. Requests module is taking my network IP and firing the request.

Are there any bug or issue with the request module or any other know issue or is there anything i am missing.

Try this:

proxy = {'http': 'http://xxx.xxx.xxx.xxx:port'}

I guess you just missed the http:// in the value of the proxy dict. Check: http://docs.python-requests.org/en/latest/user/advanced/#proxies

Documentation says:

If you need to use a proxy, you can configure individual requests with the proxies argument to any request method:

import requests
proxies = {"http": "http://10.10.1.10:3128"}
requests.get("http://example.org", proxies=proxies)

Here proxies["http"] = " http://xxx.xxx.xxx.xxx:port ". It seems you lack http://

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM