python - url 超出了最大重试次数
问题描述
我的 Django 代码有问题:
我试过这个:
requests.post('https://localhost:8000/api/test/', data=data, headers={'Content-Type': 'application/json'}, verify=False)
但我得到了这个:
{SSLError}HTTPSConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /api/test/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:852)'),))
我实现了使用 HTTP 而不是 https 来解决问题,但我想使用 https。
知道所有这些都在本地主机上,我怎么能做到这一点?
非常感谢!
编辑 :
这是来自 api 应用程序的 urls.py :
from django.urls import path, include
from django.views.decorators.csrf import csrf_exempt
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
from API import views as API views
app_name = 'api'
from API.views import LoginViewCustom
urlpatterns = [
path('test/', apiviews.Test.as_view(), name='test')
]
在其他 urls.py 中:
urlpatterns = [path('api/', include('api.urls', namespace='api'))]
解决方案
Django 的开发服务器,默认情况下通过 http 运行应用程序。因此,Max retries exceeded with url
当您尝试通过 https 访问它时,您会遇到错误。
因此,您真正想要的是使用 SSL/HTTPS 测试/运行本地开发服务器。
有几种方法可以实现这一点,但我更喜欢使用django -extensions 的RunServerPlus。他们有这个部分用于 SSL 设置。
你可以在这个问题中找到一个很好的讨论。
推荐阅读
- hyperledger-fabric - 对注册 ID、从属关系和属性进行 Hyperlefger 结构验证
- mysql - 如何在角度 9 中为每个类别加载子类别
- c - 有没有办法检查数组中的点是否存在
- python - 如何在python中以任何方向对多个元组列表进行排序?
- python - VSC 无法随机识别“Python 交互”会话中的 ctrl+c
- spring-boot - Thymeleaf 具有相同名称的多个输入标签
- java - 使用 Google Maps API 在 Android 中查找设备当前位置的纬度和经度值
- php - 如何使用帖子上的简码调用帖子对象(产品)自定义字段
- ios - Flutter 无法在 vscode 2020 上构建 iOS
- drupal - Drupal 8 - 如何检测是否已创建任何联系表单?