使用try处理套接字错误,除了[Errno 104]由对等方重置连接

时间:2016-12-03 22:58:37

标签: python sockets

我正在尝试捕获异常,但脚本会继续并在代理连接出现问题时输出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

0 个答案:

没有答案