Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getSqlCon():
- # connection to point to SQL
- con = mysql.connector.connect(
- user=config.user,
- password=config.password,
- host=config.host,
- database=config.database
- )
- return con
- def write_to_sql(query):
- result = None
- # Running in loop to avoid write issue due to db conn problem
- for i in range(0, 5):
- try:
- # Calling getAWS to get connceted to db
- con = getSqlCon()
- # Opens a db to perform operations
- cur = con.cursor()
- # Execute the query 'query'
- cur.execute(query)
- con.commit()
- # Closing the db connection
- cur.close()
- con.close()
- #print("Data Inserted")
- result = 1
- break
- except Exception as e:
- print("ERROR IN WRITE SQL. RETRYING IN 5 SEC")
- time.sleep(5)
- continue
- return result
Add Comment
Please, Sign In to add comment