pymssql.connect错误 - 意外的关键字参数'server'

时间:2015-10-01 13:18:39

标签: import module kernel connect pymssql

我正在尝试运行我已制作的程序但遇到问题。它说第8行有错误?它前几天正在工作,我不确定它是否已被更改。这可能是数据库连接错误吗?

import RPi.GPIO as GPIO
import datetime
import time
import pymssql

conn = pymssql.connect (server='192.168.0.223', user='iad', password='iad',database='inputData')
cursor = conn.cursor()
#cursor.execute('select * from yesno')
#row = cursor.fetchone()
#while row:
#       print str(row[0])
#       row = cursor.fetchone()

print("Welcome! Button live data:")

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
        input_state = GPIO.input(18)
        input_state2 = GPIO.input(23)
        if input_state == False:
                print('Happy')
                print(time.strftime("%Y-%m-%d"))
                cursor.execute("INSERT INTO buttonsPressed (inputResult, date) VALUES ('yes', '" + time.strftime("%Y-%m-%d") + "')")
                conn.commit()
                time.sleep(1)

        if input_state2 == False:
                print('Not Happy')
                print(time.strftime("%Y-%m-%d"))
                cursor.execute("INSERT INTO buttonsPressed (inputResult, date) VALUES ('no', '" + time.strftime("%Y-%m-%d") + "')")
                conn.commit()
                time.sleep(1)

我收到此错误?:

File "buttonin.py", line 8, in <module>
    conn = pymssql.connect (server='192.168.0.223', user='iad', password='iad',database='inputData')
TypeError: connect() got an unexpected keyword argument 'server'

2 个答案:

答案 0 :(得分:3)

您可以使用host =“”而不是server =“”

答案 1 :(得分:1)

我也有同样的错误。

尝试升级python pymssql库。

在Ubuntu中,您可以按照以下命令升级它: 1. sudo apt-get install freetds-dev
2. pip install pymssql --upgrade

希望这会对你有所帮助。