首页 > 解决方案 > HTTPSConnectionPool(host='localhost', port=8000): url:/index 超出最大重试次数

问题描述

我正在使用 Django 2.2.10 并python manage.py runsslserver用于在本地开发 https 站点。

我编写了一个身份验证应用程序,其视图函数将 JSON 数据返回为 ff:

def foobar(request):
    data = {
            'param1': "foo bar"
        }

    return JsonResponse(data)

我在父项目中调用这个函数如下:

def index(request):    
    scheme_domain_port = request.build_absolute_uri()[:-1]
    myauth_login_links_url=f"{scheme_domain_port}{reverse('myauth:login_links')}"

    print(myauth_login_links_url)
    
    data = requests.get(myauth_login_links_url).json()
    
    print(data)

当我导航到 https://localhost:8000myproj/index 时,我看到控制台中打印了正确的 URL,随后出现多个错误,最终导致此问题标题中显示的错误:

HTTPSConnectionPool(host='localhost', port=8000): 最大重试次数超过 url:/index (由 SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),) )

如何传递会话中使用的 SSL 证书(可能由runsslserver请求模块生成)?

标签: djangosslhttpsdjango-views

解决方案


尝试这个:

data = requests.get(myauth_login_links_url, verify=False).json()

推荐阅读