I'm trying to take some http proxies and append them to a list and then test them individually by opening them with urllib but I get the following type error. I have tried wrapping 'proxy' with str() in the test function but that returns another error.
proxies = []
with open('working_proxies.txt', 'rb') as working_proxies:
for proxy in working_proxies:
proxy.rstrip()
proxies.append(proxy)
def test(proxy):
try:
urllib.urlopen(
"http://google.com",
proxies={'http': proxy}
)
except IOError:
print "Connection error! (Check proxy)"
else:
working_proxy = True
working_proxy = False
while working_proxy == False:
myProxy = proxies.pop()
test(myProxy)
My error:
Connection error! (Check proxy)
Traceback (most recent call last):
File "proxy_hand.py", line 26, in <module>
test(proxy)
File "proxy_hand.py", line 16, in test
proxies={'http': proxy}
File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 193, in open
urltype, proxyhost = splittype(proxy)
File "/usr/lib/python2.7/urllib.py", line 1074, in splittype
match = _typeprog.match(url)
TypeError: expected string or buffer