vittorio somaschini
vittorio somaschini

Reputation: 67

Requests + Proxy Servers, IP address won't change

I am using the python shell to test requests together with proxy servers. After reading documentation (http://docs.python-requests.org/en/master/user/advanced/) and a few stackoverflow threads I am doing the following:

import requests

s = requests.session()
proxies = {'http': 'http://90.178.216.202:3128'}
s.proxies.update(proxies)
req = s.get('http://jsonip.com')

After this, if I print req.text, I get this: u'{"ip":"my current IP (not the proxy server IP I have inserted before)","about":"/about", ......}'

Can you please explain why I'm getting my computer's IP address and not the proxy server's IP address? Did I go wrong somewhere or am I expecting the wrong thing to happen here? I am new to requests + proxy servers so I would like to make sure I am understanding this.

UPDATE I also have this in my code:

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
s.headers.update(headers)

Thanks Vittorio

Upvotes: 0

Views: 3951

Answers (3)

Cheeky Lancc
Cheeky Lancc

Reputation: 19

u need to change ur get request to have the proxies used.

something like this:req = s.get('http://jsonip.com', proxies=proxies)

Upvotes: 0

t.m.adam
t.m.adam

Reputation: 15376

The site ( http://jsonip.com ) broadcasts an 'Upgrade-Insecure-Requests' header. This means that your request gets redirected to https://jsonip.com, so requests doesn't use a proxy because you don't have an https proxy in your proxies dict.

So, all you have to do is add an https proxy in proxies , eg:

proxies = {'http':'http://90.178.216.202:3128', 'https':'https://90.178.216.202:3128'}

Upvotes: 1

Mrinal
Mrinal

Reputation: 125

Instead of doing this pass user-agent

requests.post(url='abc.com',header={'user-agent':'Mozila 5.0'})

Upvotes: 0

Related Questions