__init__.py 文件源码

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

项目:autosub-bootstrapbill 作者: BenjV 项目源码 文件源码
def _conn_request(self, conn, request_uri, method, body, headers):
        for i in range(2):
            try:
                conn.request(method, request_uri, body, headers)
            except socket.gaierror:
                conn.close()
                raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
            except socket.error, e:
                if not hasattr(e, 'errno'): # I don't know what this is so lets raise it if it happens
                    raise
                elif e.errno == errno.ECONNREFUSED: # Connection refused
                    raise
                # Just because the server closed the connection doesn't apparently mean
                # that the server didn't send a response.
                pass
            except httplib.HTTPException:
                # Just because the server closed the connection doesn't apparently mean
                # that the server didn't send a response.
                pass
            try:
                response = conn.getresponse()
            except (socket.error, httplib.HTTPException):
                if i == 0:
                    conn.close()
                    conn.connect()
                    continue
                else:
                    raise
            else:
                content = ""
                if method == "HEAD":
                    response.close()
                else:
                    content = response.read()
                response = Response(response)
                if method != "HEAD":
                    content = _decompressContent(response, content)
            break
        return (response, content)
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号