How to test the proxies using Python 3?

Step 1: Download the Python from their official website.

Step 2: Open a Notepad/Text Editor and enter the following code.

import urllib.request , socket

socket.setdefaulttimeout(180)

# read the list of proxy IPs in proxyList

import tkinter as tk
from tkinter import simpledialog

ROOT = tk.Tk()

ROOT.withdraw()
# the input dialog
USER_INP = simpledialog.askstring(title="Proxy", prompt="ProxyIP:Port")

# check it out
print("LimeProxies IP:", USER_INP)
proxyList = [USER_INP] # there are two sample proxy ip

def is_bad_proxy(pip):
try:
proxy_handler = urllib.request.ProxyHandler({'http': pip})
opener = urllib.request.build_opener(proxy_handler)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
sock=urllib.request.urlopen('http://www.google.com') # change the url address here
#sock=urllib.urlopen(req)
except urllib.error.HTTPError as e:
print('Error code: ', e.code)
return e.code
except Exception as detail:

print( "ERROR:", detail)
return 1
return 0

for item in proxyList:
if is_bad_proxy(item):
print ("Bad Proxy", item)
else:
print (item, "is working")

Step 3: Save the file as proxy_checker.py

Step 4: Shift + Right Click on the folder where the file is saved and click on the Open Command window here.

Step 5: Type the following code to run the python code.

python proxy_checker.py

Step 6: Enter your proxy IP in the popup box

You will get the result as proxy working or bad proxy.

Did this answer your question?