rest.py 文件源码

python
阅读 57 收藏 0 点赞 0 评论 0

项目:Projects 作者: it2school 项目源码 文件源码
def create_connection(address):
    host, port = address
    err = None
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
        af, socktype, proto, _, sa = res
        sock = None
        try:
            sock = socket.socket(af, socktype, proto)
            sock.connect(sa)
            return sock

        except socket.error as e:
            err = e
            if sock is not None:
                sock.close()

    if err is not None:
        raise err  # pylint: disable=raising-bad-type
    else:
        raise socket.error("getaddrinfo returns an empty list")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号