4

I'm trying to read from a certain row in an MySQL data base. I'm getting an InterfaceError on line 17.

The full error:

(0, ''): InterfaceError Traceback (most recent call last): File "/var/task/handler.py", line 17, in main cur.execute(sql)

I tested the MySQL query by it self and it works just fine. The program is using the Serverless Framework hosted on Amazon Lambda.

   import json
import common
import pymysql

db = pymysql.connect(host="example.com",
                     user="admin",
                     passwd="Foo",
                     db="Bar")

def main(event, context):
    sql = "SELECT * FROM Accounts WHERE Username ='Caleb'"
    cur = db.cursor()
    cur.execute(sql)
    result = cur.fetchall()
    cur.close()
    db.close()
    data = pwd + usern
    alldata = data + result
    return dict(
        statusCode=200,
        body=json.dumps(alldata)
   )

    return response
Caleb Bird
  • 65
  • 2
  • 7
  • This error is related to the cursor or db connection being closed / reused unexpectedly see [this question](https://stackoverflow.com/questions/6650940/interfaceerror-0). Removing the `db.close()` line from the function or adding the db initialization within the function scope should resolve this – stacksonstacks Feb 28 '18 at 07:14

0 Answers0