Python pymssql error "TypeError: argument of type 'NoneType' is not iterable" when connecting to SQL server
<p>I am getting the error "TypeError: argument of type 'NoneType' is not iterable" when attempting to connect to a SQL server. I believe the error is being generated on the line where I connect to the SQL server itself, as my second print statement is never used, though I could be wrong.</p>

<p>I am using pymysql-2.1.3, and python 3.5.1</p>

<pre><code>server = getenv("####")
user = getenv("####")
password = getenv("####")
database = getenv("####")

print("hi")
conn = pymssql.connect(server, user, password, database)
print("hi2")
cursor = conn.cursor()

cursor.execute("####"
               "SELECT Name, SourceTable, SourceTableID FROM dbo.Attachment WHERE Name LIKE '%icad%'")


conn.close()
print("Connect to SQL complete")
</code></pre>

<p>This then results in the error:</p>

<pre><code>Traceback (most recent call last):
hi
  File "C:/convert.py", line 62, in &lt;module&gt;
    connect_to_sql()
  File "C:convert.py", line 15, in connect_to_sql
    conn = pymssql.connect(server, user, password, database)
  File "pymssql.pyx", line 635, in pymssql.connect (pymssql.c:10734)
  File "_mssql.pyx", line 1902, in _mssql.connect (_mssql.c:21821)
  File "_mssql.pyx", line 552, in _mssql.MSSQLConnection.__init__ (_mssql.c:5891)
TypeError: argument of type 'NoneType' is not iterable

Process finished with exit code 1
</code></pre>

<p>I have no idea why this is happening - the connect function follows the pymssql documentation exactly. </p>

<p>I am importing the following libraries if it helps:</p>

<pre><code>import os
from os import getenv
import pymssql
import subprocess
</code></pre>

<p>I have removed the database credentials in this question, however I know they work as I am able to connect to the SQL server via the management studio. </p>

<p>Does anyone know why this code doesn't work?</p>

<p>This code is contained within a function called 'connect_to_sql():' and is then used afterwards, however some of the following code is sensitive so I have only cut these particular lines out. I hope it is enough.</p>