3

While I'm trying to connect to my localhost, I get [SSL: WRONG_VERSION_NUMBER] error. I'm using '8080' port by default. Previously, I was getting ProxyError, then I changed my url from 'http' to 'https' and now I get SSLError. I've checked some solutions, which prompts to change the port number. Does it have to do anything with the port number, or something else?

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

The error is as follows

stacktrace:

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)')))
7
  • do you have SSL certificate? Commented Jul 6, 2019 at 11:37
  • No, how can I have it? Commented Jul 6, 2019 at 12:05
  • Otherwise how do you run your endpoint with https? Commented Jul 6, 2019 at 12:49
  • I dont know much about these protocols. How can I add ssl certificate? Commented Jul 6, 2019 at 13:01
  • It's okay, just search on Google. You'll find lots of online resources. Commented Jul 6, 2019 at 13:16

1 Answer 1

8
endpoint = 'https://****:8080/MyApp/services/DBConnection/callLoginProcedure'

From the your edits in your previous question the original URL can be retrieved. When trying this it is clear that the endpoint you are trying to access only supports HTTP on the given port 8080 and not HTTPS as you are trying to use.

[SSL: WRONG_VERSION_NUMBER] Error

The error you see stems from the attempt to access a site with HTTPS which only can do HTTP. Your clients starts a TLS handshake by sending a ClientHello and expects the server to reply with a ServerHello. Only, the server sends a plain HTTP response. The client then tries to interpret this response as TLS ServerHello which includes figuring out the TLS protocol version from some bytes at a specific position in the response. Since this is no TLS response is expected the information there make no sense when interpreted as TLS which results in this strange error message.

The proper way is to access the URL by HTTP not HTTPS. If you get problems there (you mention some ProxyError without details) then you need to fix these problems and not just attempt to access the site by HTTPS - which as you see only causes other problems.

Sign up to request clarification or add additional context in comments.

2 Comments

Helpful answer, thanks. Do you have any suggestion to solve this "ProxyError"?
@Exqra: Either you are using a proxy you should not use or you are using a proxy which is blocking access (common in corporate networks) or maybe something else. Unfortunately, with only ProxyError one can not narrow down what exactly the problem is. But hopefully you know more about your working environment and can decide which of the possible causes I gave might be the likely one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.