【问题标题】:HTTPSConnectionPool(host='localhost', port=8000): Max retries exceeded with url:/indexHTTPSConnectionPool(host='localhost', port=8000): url:/index 超出最大重试次数
【发布时间】:2020-11-18 04:49:56
【问题描述】:

我正在使用 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] 证书验证失败 (_ssl.c:852)'引起),))

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

【问题讨论】:

标签: django ssl https django-views


【解决方案1】:

试试这个:

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

【讨论】:

  • 在这种情况下,SO 是一种不可替代的资源。谢谢你,谢谢你,谢谢你! :)
猜你喜欢
  • 2020-10-31
  • 1970-01-01
  • 2014-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-31
  • 2019-09-24
相关资源
最近更新 更多