本文整理汇总了Python中socks.ProxyConnectionError方法的典型用法代码示例。如果您正苦于以下问题:Python socks.ProxyConnectionError方法的具体用法?Python socks.ProxyConnectionError怎么用?Python socks.ProxyConnectionError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socks
的用法示例。
在下文中一共展示了socks.ProxyConnectionError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SOCKS5_connect_timeout_test
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyConnectionError [as 别名]
def SOCKS5_connect_timeout_test():
s = socks.socksocket()
s.settimeout(0.0001)
s.set_proxy(socks.SOCKS5, "8.8.8.8", 80)
try:
s.connect(("ifconfig.me", 80))
except socks.ProxyConnectionError as e:
assert str(e.socket_err) == "timed out"
示例2: _open_socket
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyConnectionError [as 别名]
def _open_socket(addrinfo_list, sockopt, timeout):
err = None
for addrinfo in addrinfo_list:
family, socktype, proto = addrinfo[:3]
sock = socket.socket(family, socktype, proto)
sock.settimeout(timeout)
for opts in DEFAULT_SOCKET_OPTION:
sock.setsockopt(*opts)
for opts in sockopt:
sock.setsockopt(*opts)
address = addrinfo[4]
try:
sock.connect(address)
err = None
except ProxyConnectionError as error:
err = WebSocketProxyException(str(error))
err.remote_ip = str(address[0])
continue
except socket.error as error:
error.remote_ip = str(address[0])
try:
eConnRefused = (errno.ECONNREFUSED, errno.WSAECONNREFUSED)
except:
eConnRefused = (errno.ECONNREFUSED, )
if error.errno in eConnRefused:
err = error
continue
else:
raise error
else:
break
else:
raise err
return sock
示例3: _open_socket
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyConnectionError [as 别名]
def _open_socket(addrinfo_list, sockopt, timeout):
err = None
for addrinfo in addrinfo_list:
family, socktype, proto = addrinfo[:3]
sock = socket.socket(family, socktype, proto)
sock.settimeout(timeout)
for opts in DEFAULT_SOCKET_OPTION:
sock.setsockopt(*opts)
for opts in sockopt:
sock.setsockopt(*opts)
address = addrinfo[4]
err = None
while not err:
try:
sock.connect(address)
except ProxyConnectionError as error:
err = WebSocketProxyException(str(error))
err.remote_ip = str(address[0])
continue
except socket.error as error:
error.remote_ip = str(address[0])
try:
eConnRefused = (errno.ECONNREFUSED, errno.WSAECONNREFUSED)
except:
eConnRefused = (errno.ECONNREFUSED, )
if error.errno == errno.EINTR:
continue
elif error.errno in eConnRefused:
err = error
continue
else:
raise error
else:
break
else:
continue
break
else:
if err:
raise err
return sock
示例4: fly
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyConnectionError [as 别名]
def fly():
"""
Main function
"""
# Initial
args = parse_arguments()
try:
proxy_connect(args)
init(args)
# Twitter API connection problem
except TwitterHTTPError as e:
printNicely('')
printNicely(
magenta('We have connection problem with twitter REST API right now :('))
detail_twitter_error(e)
save_history()
sys.exit()
# Proxy connection problem
except (socks.ProxyConnectionError, URLError):
printNicely(
magenta('There seems to be a connection problem.'))
printNicely(
magenta('You might want to check your proxy settings (host, port and type)!'))
save_history()
sys.exit()
# Spawn stream thread
target = args.stream.split()[0]
if target == 'mine':
spawn_personal_stream(args)
else:
try:
stuff = args.stream.split()[1]
except:
stuff = None
spawn_dict = {
'public': spawn_public_stream,
'list': spawn_list_stream,
}
spawn_dict.get(target)(args, stuff)
# Start listen process
time.sleep(0.5)
g['reset'] = True
g['prefix'] = True
listen()