일부 Python 코드에서 쿼리를 실행하려고하면 InterfaceError : (0, '')가 표시됩니다. 나는 아래에서 사용하고있는 코드를 게시 할 것이다.mysqldb를 사용하여 파이썬에서 InterfaeError 0 수신
def insert_into_table(schema, table, connection, filename = 'pathToAnInputFile'):
x = connection.cursor()
with open(filename, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
next(reader)
for line in reader:
query = "INSERT INTO {0}.{1} (field1, field2, field3) VALUES ('{2}', '{3}', '{4}')".format(table, schema, line[0], line[1], line[2])
print query
x.execute(query)
conn.commit()
conn.close()
import MySQLdb
import csv as csv
conn = MySQLdb.connect("localhost", "nottheusername", "notthepassword", db="adb")
insert_into_table('atablename', 'adb', conn)
그리고 여기 내가이 특정 오류에 대한 자세한 내용은 몇 가지 검색을 수행 한
받고 있어요 출력이며, 그것은 일반적으로 글로벌 커서를 갖는 연관되는 것처럼 보인다 그것을 사용하고있는 함수 내에서 생성되는 로컬 커서가 아니라 생성 된 것이지만이 경우에는 문제가되지 않습니다. 아니면 최소한 그렇다면 나에게는 분명하지 않습니다.INSERT INTO adb.atablename (field1, field2, field3) VALUES ('dogs', 'puppies', 'Nov 21, 2017') --------------------------------------------------------------------------- InterfaceError Traceback (most recent call last) in() ----> 1 insert_into_table('atablename', 'adb', conn)
<ipython-input-24-02df4bf9bbdb> in insert_into_table(schema, table, connection, filename) 8 query = "INSERT INTO {0}.{1} (RMS_CLASS_NM, campaign, ad_group) VALUES ('{2}', '{3}', '{4}')".format(table,
schema, line[0], line[1], line[2]) 9 print query ---> 10 x.execute(query) 11 conn.commit() 12
C:\Users\braddavi\AppData\Local\Continuum\Anaconda2\lib\site-packages\MySQLdb\cursors.pyc
in execute(self, query, args) 224 except Exception: 225 exc, value = sys.exc_info()[:2] --> 226 self.errorhandler(self, exc, value) 227 self._executed = query 228 if not self._defer_warnings: self._warning_check()
C:\Users\braddavi\AppData\Local\Continuum\Anaconda2\lib\site-packages\MySQLdb\connections.pyc
in defaulterrorhandler(failed resolving arguments) 34 del connection 35 if isinstance(errorvalue, BaseException): ---> 36 raise errorvalue 37 if errorclass is not None: 38 raise errorclass(errorvalue)
InterfaceError: (0, '')
또한 쿼리를 인쇄 쿼리 행에서 인쇄하여 mysqldb 터미널에서 직접 실행하면 아무런 문제없이 데이터가 실행되고 삽입된다는 점도 지적해야합니다.
누구든지 도움을받을 수 있다면 크게 감사하겠습니다.
모두에게 행복한 휴가. Brad