pyi_lib_requests.py 文件源码

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

项目:mac-package-build 作者: persepolisdm 项目源码 文件源码
def main():

    SERVER_PORT = 8443
    httpd = None

    # Since unit tests run in parallel, the port may be in use, so
    # retry creating the server while incrementing the port number
    while SERVER_PORT < 8493:  # Max 50 retries
        try:
            # SSL server copied from here:
            # http://www.piware.de/2011/01/creating-an-https-server-in-python/
            httpd = BaseHTTPServer.HTTPServer(
                ('localhost', SERVER_PORT),
                SimpleHTTPServer.SimpleHTTPRequestHandler)
        except socket.error as e:
            if e.errno == 98:  # Address in use
                SERVER_PORT += 1
                continue
            else:
                # Some other socket.error
                raise
        else:
            # Success
            break
    else:
        # Did not break from loop, so we ran out of retries
        assert False, "Could not bind server port: all ports in use."

    httpd.socket = ssl.wrap_socket(
        httpd.socket, certfile=SERVER_CERT, server_side=True,
        ssl_version=ssl.PROTOCOL_TLSv1,
    )

    def ssl_server():
        httpd.serve_forever()

    # Start the SSL server
    thread = threading.Thread(target=ssl_server)
    thread.daemon = True
    thread.start()

    # Wait a bit for the server to start
    time.sleep(1)

    # Use requests to get a page from the server
    requests.get(
        u"https://localhost:{}".format(SERVER_PORT),
        verify=SERVER_CERT)
    # requests.get("https://github.com")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号