title: How to connect using python-tds driver to sql server which is forcing encryption?
body: <p>I'm trying to connect to SQL Server 2016 with python-tds driver using NTLM authentication. The sql server is forcing encryption (SQL Configuration manager) as per this screenshot. There is no certificate attached to it on the next tab.</p>
  <p><a href="https://i.stack.imgur.com/oME2G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oME2G.png" alt="enter image description here" /></a></p>
  <p>The server is on AWS EC2 machine but I don't think this bring any difference? This code (which is confirmed to work for a different server with no encryption):</p>
  <pre><code>import pytds
  from pytds.login import NtlmAuth
  
  ntlm = NtlmAuth(user_name='domain\username', password='password')
  pytds_conn = pytds.connect(dsn='11.22.33.44', database='master',
                             port=1433, auth=ntlm, autocommit=True)
  </code></pre>
  <p>gives this error:</p>
  <p><em>pytds.tds_base.Error: Client does not have encryption enabled but it is required by server, enable encryption and try connecting again</em></p>
  <p>I then tried to use <code>cafile</code> parameter within <code>pytds.connect</code> function. So I created .cer file and corresponding .pem file following this link : <a href="http://www.richardnichols.net/2014/03/creating-and-importing-an-external-certificate-to-sql-server/" rel="nofollow noreferrer">http://www.richardnichols.net/2014/03/creating-and-importing-an-external-certificate-to-sql-server/</a></p>
  <p>After uploading the .cer certificate using the query:</p>
  <pre><code>CREATE CERTIFICATE testCer   
      FROM FILE = 'c:\Temp\test.cer' 
  </code></pre>
  <p>and adding parameter <code>cafile=test.pem</code> to pytds.connect I got this error:</p>
  <p><em>OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]</em></p>
  <p>Do you know how (or whether at all) can I make the python-tds NTLM connection working when the encryption is forced and there is no certificate attached to it in SQL Server Network Configuration?</p>