1

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.

Raj
  • 271
  • 1
  • 3
  • 7

2 Answers2

2

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

Mathias
  • 6,777
  • 2
  • 20
  • 32
  • Does the proxy need username/pawssword? – Mathias Aug 07 '14 at 14:41
  • No proxy does not have any username. I think i got the issue. Requests in python does not support for https. It only supports for http proxies. If you try using https it will not use the proxy instead it will use your local IP address for the request. – Raj Aug 08 '14 at 04:10
  • What? requests supports https for sure. – Mathias Aug 08 '14 at 05:49
  • I tried it using proxy = {'https': 'https://xxx.xxx.xxx.xxx:port'} but it didn't worked it internally called my original IP. If i modify it to proxy = {'http': 'http://xxx.xxx.xxx.xxx:port'} then it started working for me. – Raj Aug 08 '14 at 16:03
0

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://

selfboot
  • 1,490
  • 18
  • 23