title: Python - AttributeError: 'NoneType' object has no attribute 'cursor'
body: <p>I have the following code:</p>
  
  <pre><code>import pyodbc
  
  conn = pyodbc.connect('DSN=QueryBuilder')
  cursor = conn.cursor()
  stringA = "SELECT GrantInformation.Call FROM GrantInformation"
  cursor.execute(stringA)
  rows = cursor.fetchall()
  </code></pre>
  
  <p>Its worked fine for years, but all of a sudden it has stopped working today with the following traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/nicholas/Desktop/test.py", line 6, in &lt;module&gt;
      cursor = conn.cursor()
  AttributeError: 'NoneType' object has no attribute 'cursor'
  </code></pre>
  
  <p>The code still works in Jupyter Notebook, but no longer works outside i.e. in Pycharm/IDLE</p>
  
  <p>If I run in Pycharm:</p>
  
  <pre><code>print(pyodbc.dataSources())
  print(pyodbc.drivers())
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>none
  none
  </code></pre>
  
  <p>If I do it in Jupyter Notebook, I get:</p>
  
  <pre><code>{'Visio Database Samples': 'Microsoft Access Driver (*.mdb, *.accdb)', 'dBASE Files': 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)', 'Excel Files': 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)', 'MS Access Database': 'Microsoft Access Driver (*.mdb, *.accdb)', 'QueryBuilder': 'SQL Server', 'QueryBuilder_Beta': 'SQL Server', 'MIDAS': 'SQL Server', 'Querybuilder_YearEnd': 'SQL Server', 'ResearchFish': 'SQL Server', 'ESRCContacts': 'SQL Server', 'ESRCContactsDEV': 'SQL Server', 'Sample Amazon Redshift DSN': 'Amazon Redshift (x64)'}
  
  ['SQL Server', 'SQL Server Native Client 10.0', 'Amazon Redshift (x64)', 'SQL Server Native Client 11.0', 'PostgreSQL ANSI(x64)', 'PostgreSQL Unicode(x64)', 'ODBC Driver 11 for SQL Server', 'ODBC Driver 13 for SQL Server']
  </code></pre>
  
  <p>I am losing the plot, as I rely on this code a lot for doing all my work, but nothing I am doing is fixing the issue i.e. reinstalling Python, pyodbc etc</p>