Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Requests Proxies not working

Tags:

python

proxy

I am trying to access a proxy, that I have ping multiple times and is online, to do a search.

import requests
import re

s = requests.Session() 
s.proxies = {'http': 'http://11.22.33.4455'}

r = s.get('https://www.iplocation.net/find-ip-address')

data = r.text

regex = r"1.2.3.45"  # Proxy IP
regex2 = r"6.7.8.99"  # My IP

matches = re.findall(regex, data)
matches2 = re.findall(regex2, data)

print(matches)
print(matches2)  # Always prints out my current IP and not my proxy

This is my code. I use regular expressions to search the html code for mentions of the IP and it always only returns my current IP. I tried different websites that tell me my IP and everyone of them returns my current IP and not my proxy. Any suggestion on what I am doing wrong.

like image 201
David Arico Avatar asked Jun 26 '17 16:06

David Arico


People also ask

How do I use a proxy request in Python?

In order to use proxies in the requests Python library, you need to create a dictionary that defines the HTTP, HTTPS, and FTP connections. This allows each connection to map to an individual URL and port. This process is the same for any request being made, including GET requests and POST requests.

How do I enable proxy in Python?

To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections. This variable should be a dictionary that maps a protocol to the proxy URL. Additionally, make a url variable set to the webpage you're scraping from.


1 Answers

Your proxy is http while your request address is a https. You need to have another proxy for https requests.

like image 158
Ben Avatar answered Oct 02 '22 22:10

Ben