0

I am using Python library pymssql to connect to a database. I have never used it before so the error might look trivial.

from os import getenv
import pymssql

server = getenv("192.xxx.xxx.xx") 
user = getenv("john.constantine")
password = getenv("xxxxxxx")

conn = pymssql.connect(server, user, password, "tempdb")
cursor = conn.cursor()

cursor.execute('SELECT * from table')
rows = cursor.fetchall()
for row in rows:
    print row

conn.close()

I get the following error:

Traceback (most recent call last):
  File "C:\Users\Documents\Demo_DB.py", line 8, in <module>
    conn = pymssql.connect(server, user, password, "tempdb")
  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
[Finished in 0.2s with exit code 1]

I connect to DB using these credentials. enter image description here

8
  • Your table in tempdb is called table? Commented Jun 1, 2017 at 23:34
  • @ShawnMehan The Table is under "Databases" Commented Jun 1, 2017 at 23:37
  • 1
    server = getenv("192.xxx.xx.xx") is going to set server to None, unless you actually have an environment variable named 192.xxx.xx.xx. That's probably what's given you the None which is throwing the exception. (Same for your other getenv.) Commented Jun 1, 2017 at 23:38
  • @ShawnMehan I have updated the question. That's how I connect to the DB. Commented Jun 1, 2017 at 23:42
  • 1
    If you know the server address is 192.111.111.11, why on earth are you calling getenv()? Just do server = '192.111.111.11' and be done with it. Commented Jun 1, 2017 at 23:47

0

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.