파이썬 3.3에서 pymssql
을 사용하여 Mssql db와 통신합니다. 그리고이 데이터베이스에 튜플에서 사용자로부터 데이터를 저장하기 위해 노력하고 있어요,하지만 난이 이상한 오류가 계속 :튜플을 mssql 데이터베이스에 삽입 할 수 없습니다
pymssql.ProgrammingError: (102, b"Incorrect syntax near '\\'.DB-Lib error message 102, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
내 방법을, 오류가 마지막 줄에 표시됩니다 :
user.password = user.password.encode('utf_8')
user.password = encrypt_RSA(user.password)
cursor.execute('INSERT INTO Usertable VALUES(%i, \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')' % user.get_usertuple())
내가 잘못 여기서 뭐하는 거지
def encrypt_RSA(message, public_key_loc = "pubkey.pem"):
'''
param: public_key_loc Path to public key
param: message String to be encrypted
return encoded encrypted string
'''
key = open(public_key_loc, "r").read()
rsakey = RSA.importKey(key)
rsakey = PKCS1_OAEP.new(rsakey)
encrypted = rsakey.encrypt(message)
return encrypted
사람이 말할 수 :
나는 그것이 인코딩 할 수있는 뭔가 및 암호화를 가지고 의심? 그리고 그것을 고치는 방법?
편집 : 내 쿼리는 이제 다음과 같습니다
cursor.execute('INSERT INTO Usertable VALUES(%i, %s, %s, %s, %s, %s, %s)' % user.get_usertuple())
But that gives me another error: pymssql.OperationalError: (103, b"The identifier that starts with (LONG TEXT) is too long. Maximum length is 128.DB-Lib error message 103, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 102, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
cursor.execute를 실행하는 대신 쿼리를 인쇄하여 쿼리가 올바르게 렌더링되는지 확인하려고 했습니까? – frlan
'SQL 서버에서 메시지 확인 '을 했습니까? – njzk2
괜찮 았던 것처럼 보입니다. 문제는 바이트 데이터라는 사실과 관련이 있다고 생각합니다. 비밀 번호는 다음과 같이 출력됩니다 : b'x10 // ... 등. 그리고 나는 아마도 b '가 거기에있는 것과 어떤 문제가 있다고 추측하고 있습니까? –