Except exception as e : ERROR AS INVALID SYNTAX

i got error in this help out.

except Exception as e:

full code
while True:
print (“Reading sensor value”)
response = mybolt.analogRead(‘A0’)
data = json.loads(response)
print("Sensor value is: " + str(data[‘value’]))
sensor_value = int(data[‘value’])
if sensor_value > maximum_limit or sensor_value < minimum_limit:
print(“Making request to Twilio to send a SMS”)
response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
print("Response received from Twilio is: " + str(response))
print(“Status of SMS at Twilio is :” + str(response.status))
except Exception as e:
print (“Error occured: Below are the details”)
print (e)


Please make sure you indent the code as per python’s guidelines. We have mentioned the same in the training as well.

Also, you haven’t mentioned the exact error that you are facing.

Hello sir,

I am getting syntax error while executing the temperature sensor coding. The coding -

The error is -

except syntax error

Kindly guide me sir.
Thank you so much Sir.

@suchetakumari43 as per your code snippet, the indentation for the except block is not correct. In python there is try-except block in which the code of except block runs only if the try block is false.

Just make sure that the except block is at the same level as that of try block. Currently the except block is idented with the if block which is incorrect. It will solve your problem :slight_smile:

Thank you so much sir. Its works
Have a nice day

Your welcome @suchetakumari43