我正在尝试捕获异常,但脚本会继续并在代理连接出现问题时输出none
,例如Socket Error: Socket error: [Errno 104] Connection reset by peer
以及Google的到期日期
import socket
import socks
import whois
import requests
try:
r = requests.get('http://gimmeproxy.com/api/getProxy?protocol=socks5&maxCheckPeriod=3600').json()
socks.set_default_proxy(socks.SOCKS5, r['ip'], int(r['port']))
print(r['ip'], int(r['port']))
socket.socket = socks.socksocket
w = whois.whois('google.com')
print(w.expiration_date)
except Exception as msg:
print(msg) #never actually prints this