[英]Python-Django [SSL: WRONG_VERSION_NUMBER] Error
在嘗試連接到本地主機時,出現[SSL:WRONG_VERSION_NUMBER]錯誤。 我默認使用“ 8080”端口。 以前,我收到了ProxyError,然后將URL從“ http”更改為“ https”,現在得到了SSLError。 我已經檢查了一些解決方案,提示您更改端口號。 它與端口號有關系嗎?
views.py:
endpoint = 'https://****:8080/MyApp/services/DBConnection/callLoginProcedure'
def index(request):
post = request.POST
if request.POST.get('login_button'):
qd = QueryDict(mutable=True)
qd.update(
inputPhoneNumber=request.POST.get('phone_num'),
inputPassword=request.POST.get('password')
)
response = requests.post('{}?{}'.format(endpoint, qd.urlencode()), verify=False)
result = response.json()
messages.info(request, result)
return render(request, 'login/index.html')
錯誤如下
堆棧跟蹤:
Django Version: 2.2.3
Python Version: 3.7.3
Installed Applications:
['login',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware']
Traceback:
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
603. chunked=chunked)
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py" in _make_request
344. self._validate_conn(conn)
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py" in _validate_conn
843. conn.connect()
File "C:\Program Files\Python37\lib\site-packages\urllib3\connection.py" in connect
370. ssl_context=context)
File "C:\Program Files\Python37\lib\site-packages\urllib3\util\ssl_.py" in ssl_wrap_socket
368. return context.wrap_socket(sock)
File "C:\Program Files\Python37\lib\ssl.py" in wrap_socket
412. session=session
File "C:\Program Files\Python37\lib\ssl.py" in _create
853. self.do_handshake()
File "C:\Program Files\Python37\lib\ssl.py" in do_handshake
1117. self._sslobj.do_handshake()
During handling of the above exception ([SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)), another exception occurred:
File "C:\Program Files\Python37\lib\site-packages\requests\adapters.py" in send
449. timeout=timeout
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py" in urlopen
641. _stacktrace=sys.exc_info()[2])
File "C:\Program Files\Python37\lib\site-packages\urllib3\util\retry.py" in increment
399. raise MaxRetryError(_pool, url, error or ResponseError(cause))
During handling of the above exception (HTTPSConnectionPool(****): Max retries exceeded with url: /MyApp/services/DBConnection/callLoginProcedure?inputPhoneNumber=231412&inputPassword=4211 (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)')))), another exception occurred:
File "C:\Program Files\Python37\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Program Files\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "C:\Program Files\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\TOLGA\Desktop\PythonWebProjects\WebLogin\login\views.py" in index
53. response = requests.post('{}?{}'.format(endpoint, qd.urlencode()), verify=False)
File "C:\Program Files\Python37\lib\site-packages\requests\api.py" in post
116. return request('post', url, data=data, json=json, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\api.py" in request
60. return session.request(method=method, url=url, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\sessions.py" in request
533. resp = self.send(prep, **send_kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\sessions.py" in send
646. r = adapter.send(request, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\adapters.py" in send
514. raise SSLError(e, request=request)
Exception Type: SSLError at /login/
Exception Value: HTTPSConnectionPool(***) (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)')))
endpoint = 'https://****:8080/MyApp/services/DBConnection/callLoginProcedure'
從上一個問題的編輯中,可以檢索原始URL。 嘗試此操作時,很明顯,您嘗試訪問的端點僅在給定的端口8080上支持HTTP,而在嘗試使用的端口上不支持HTTPS。
[SSL:WRONG_VERSION_NUMBER]錯誤
您看到的錯誤是由於嘗試使用只能執行HTTP的HTTPS訪問站點而引起的。 您的客戶端通過發送ClientHello啟動TLS握手,並希望服務器以ServerHello進行回復。 服務器僅發送純HTTP響應。 然后,客戶端嘗試將此響應解釋為TLS ServerHello,其中包括從響應中特定位置的某些字節中確定TLS協議版本。 由於這不是TLS響應,因此將其解釋為TLS時,該信息沒有意義,這會導致出現此奇怪的錯誤消息。
正確的方法是通過HTTP而不是HTTPS訪問URL。 如果在那里遇到問題(您提到了一些ProxyError,但沒有詳細信息),那么您需要解決這些問題,而不僅僅是嘗試通過HTTPS訪問該網站-如您所見,這只會導致其他問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.