How to upload data from raspberry pi to mySQL, geting errors

2018-06-24 05:44:41

Basically i am trying to upload the data collected from my raspberry pi to mysql, I have a table called DHT_data with columns 'datetime' using datatype timestamp, 'temp' using datatype numeric, 'hum' using datatype numeric as well. However using my python script shown below i keep getting errors like indentation error or syntax error. I am currently new to programming so i don't really know whats the problem. Would appreciate any help in finding the solution or rectifying any errors with the script since i am not sure if it works yet

import time

import Adafruit_DHT

import MySQLdb

import sys

from time import sleep

DHTpin = 4

try:

db = MySQLdb.connect("localhost", "root", "dmitiot", "IOTassignmentBobo")

curs = db.cursor()

print("Successfully connected to database!")

except:

print("Error connecting to mySQL database")

update = True

while update:

humidity, temperature = Adafruit_DHT.read_retry(11, DHTpin)

if humidity is not None and temp