Python3: ReferenceError: weakly-referenced object no longer exists
<p>Below code works perfectly in python2 with MySQLDB, how can I make it Python3 compatible?</p>

<p>I have debugged and searched for similar questions. </p>

<blockquote>
  <p>Error:
  Exception ignored in: > Traceback (most recent call last): File > > > "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 41, in del File > "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 47, in close ReferenceError: weakly-referenced object no longer exists –</p>
</blockquote>

<pre><code>class Database():

    def __init__(self):
        self.host = 'localhost'
        self.user = 'user'
        self.password = 'pwd'  
        self.db = 'dbname'
        self.connection = pymysql.connect(host=self.host, user=self.user, passwd=self.password, db=self.db,use_unicode=True, charset="utf8")
        self.cursor = self.connection.cursor()

    def storeToDB(self,ID,string,g,e):
        import datetime

        curr_time = datetime.datetime.now()
        status = 0
        try:
            self.cursor.execute("""INSERT INTO master_data (`job_id`,`sstring`,`grl`,`erl`,`status`,`insert_timestamp`) \
            VALUES (%s,%s,%s,%s,%s,%s)""",(jobID,search_string,g,e,status,curr_time))
            self.connection.commit()
        except:
            self.connection.rollback()
if __name__ == "__main__":
    db = Database()
    db.storeToDB(20,"hello","something.com","e.com")
</code></pre>