简体   繁体   English

最大重试次数超过 url

[英]Max retries exceeded with url

I have a problem with my Django code:我的 Django 代码有问题:

I tried this:我试过这个:

requests.post('https://localhost:8000/api/test/', data=data, headers={'Content-Type': 'application/json'}, verify=False)

But I got this:但我得到了这个:

{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)'),))

I achieved to solve the problem using HTTP instead of https but I want to use https.我使用 HTTP 而不是 https 来解决问题,但我想使用 https。

How can I do this knowing that all of this is on the localhost?知道所有这些都在本地主机上,我该怎么做?

Thank you very much!非常感谢你!

EDIT:编辑:

Here is the urls.py from the api app:这是来自 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')
]

and in the other urls.py:在另一个 urls.py 中:

urlpatterns = [path('api/', include('api.urls', namespace='api'))]

Django's development server, by default run the application over http. Therefore you are getting Max retries exceeded with url error as you try to reach it via https. Django 的开发服务器,默认情况下在 http 上运行应用程序。因此,当您尝试通过 https 访问它时,您会收到Max retries exceeded with url错误。

Therefore what you actually want is to test/run the local development server with SSL/HTTPS.因此,您真正想要的是使用 SSL/HTTPS 测试/运行本地开发服务器。

There are several way to achieve this, But what I prefer is to use RunServerPlus from django-extensions .有几种方法可以实现这一点,但我更喜欢使用django-extensions中的RunServerPlus They have this section for SSL setup.他们有此部分用于 SSL 设置。

You can find a good discussion in this question .您可以在这个问题中找到很好的讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM