0

I am using a docker container running django application.

T get the below error whenever I try to run function that manipulates data on 2 separate databases:

error: [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol] (-1) (SQLDriverConnect)')

This is the function I run

def preStepBtn3(request):
    sourcePE = request.GET.get('sourcePE')
    targetPE = request.GET.get('targetPE')
    inputFTID = request.session['username']
    datetime_object = datetime.datetime.now()
    step_name = "preStepBtn3"
    table_name = "null"
    Action_taken = "change router status to MIG"
    MassivePortalSessionID = request.session['MassivePortalSessionID']

    try:
        with connections['DataAdmin'].cursor() as cursor:
            sql = """DECLARE @out nvarchar(max); exec DTA.mig_sop_ce_status2mig_django 0, %s, @param_out = @out OUTPUT; SELECT @out AS the_output; """
            params = [sourcePE]
            cursor.execute(sql, params)            
            rows = cursor.fetchall()
            result = []
            result.append(rows)
            logDB_sql(MassivePortalSessionID, inputFTID, sourcePE, targetPE,
                      table_name, step_name, datetime_object, Action_taken)
            print("data inserted in log DB")
            while rows:
                print(rows)
                if cursor.nextset():
                    result.append(cursor.fetchall())
                else:
                    print(result)
                    return JsonResponse(result,  safe=False)
    except Exception as ex:
        error = ex
        print(error)
        context = {'text': error}
        logDB_sql(MassivePortalSessionID, inputFTID, sourcePE, targetPE,
                  table_name, step_name, datetime_object, Action_taken)
        print("data inserted in log DB during exception")
        return render(request, 'posts/textArea.html', context)

Whenever I remove the logDB_sql it works perfectly. This is code for logDB_sql

def logDB_sql(MassivePortalSessionID, inputFTID, sourcePE, targetPE, table_name, step_name, datetime_object, Action_taken):
    params = [MassivePortalSessionID, inputFTID, sourcePE, targetPE,
              table_name, step_name, datetime_object, Action_taken]
    print(targetPE)
    print(sourcePE)
    print(MassivePortalSessionID)
    print(inputFTID)
    if sourcePE != None and MassivePortalSessionID != None and targetPE != None and inputFTID != None:
        sql = " insert into MASSIVE_MIGRATION_PORTAL_LOGS values (%s,%s,%s,%s,%s,%s,%s,%s )"
        print(sql)
        print(params)
        with connections['logDB'].cursor() as cursor:
            cursor.execute(sql, params)
            cursor.close()
            print("data inserted")

This is connection info in settings.py. note that they are different hosts

    'logDB': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'log_db',
        'HOST': 'xx.xx.xx.xx',
        'USER': 'user1',
        'PASSWORD': 'password1',

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'timeout': 1000,
        }

    },

    'DataAdmin': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'another_db',
        'HOST': 'xx.xx.xx.xx',
        'USER': 'user1,
        'PASSWORD': 'password1',

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'timeout': 1000,
        }
    },

}

And this is the error message

 File "/app/posts/views.py", line 387, in preStepBtn2
    table_name, step_name, datetime_object, Action_taken)
  File "/app/posts/views.py", line 90, in logDB_sql
    with connections['logDB'].cursor() as cursor:
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
    return self._cursor()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 232, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.6/site-packages/sql_server/pyodbc/base.py", line 307, in get_new_connection
    timeout=timeout)
django.db.utils.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol] (-1) (SQLDriverConnect)')

I have tried it locally on my windows machine and it works without any issues, not sure why it is failing when i move it to docker container.

Any ideas?

2
  • What is your SQL Server version? Older versions of SQL Server (e.g.: 2008 R2) don't support the TLS 1.2 protocol required by modern client drivers, especially if they're using OpenSSL. You can manually confirm server support by way of openssl s_client --host <YourServerIP> --port 1433 with the -tls1, -tls1_1, -tls1_2 and -tls1_3 switches. Commented Apr 9, 2020 at 3:30
  • @AlwaysLearning i have tried and got: CONNECTED(00000003) write:errno=0 no peer certificate available No client certificate CA names sent SSL handshake has read 0 bytes and written 188 bytes Verification: OK New, (NONE), Cipher is (NONE) Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE No ALPN negotiated SSL-Session: Protocol : TLSv1.2 Cipher: 0000 Session-ID: Session-ID-ctx: Master-Key: PSK identity: None PSK identity hint:None SRP username:None Start Time:1586453378 Timeout : 7200 (sec) Verify return code: 0 (ok) Extended master secret: no Commented Apr 9, 2020 at 17:35

1 Answer 1

3

I have resolved this issue by updating the openssl.cnf file in /etc/ssl/

Changed MinProtocol = TLSv1.2 to MinProtocol = TLSv1.0 & CipherString = DEFAULT@SECLEVEL=2 to CipherString = DEFAULT@SECLEVEL=1

Hope this helps.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.