Guest User

Untitled

a guest
Jan 9th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. def getSqlCon():
  2.  
  3. # connection to point to SQL
  4. con = mysql.connector.connect(
  5. user=config.user,
  6. password=config.password,
  7. host=config.host,
  8. database=config.database
  9. )
  10.  
  11. return con
  12.  
  13.  
  14.  
  15. def write_to_sql(query):
  16. result = None
  17. # Running in loop to avoid write issue due to db conn problem
  18. for i in range(0, 5):
  19. try:
  20. # Calling getAWS to get connceted to db
  21. con = getSqlCon()
  22. # Opens a db to perform operations
  23. cur = con.cursor()
  24. # Execute the query 'query'
  25. cur.execute(query)
  26. con.commit()
  27. # Closing the db connection
  28. cur.close()
  29. con.close()
  30. #print("Data Inserted")
  31. result = 1
  32. break
  33.  
  34. except Exception as e:
  35. print("ERROR IN WRITE SQL. RETRYING IN 5 SEC")
  36. time.sleep(5)
  37. continue
  38.  
  39. return result
Add Comment
Please, Sign In to add comment