Python error: except Exception as e:

It is showing syntax error even if i m writing the code correctly then also can anyone help me with this
I have seen other solutions on bolt forum but i am unable to find the perfect solution for my error


Please help me with this .

Your except indentation is wrong.
Except block should come right below your try block(same alignment as try block).

Hope this helped you.

1 Like

Hello, In Python space is Sensitive and Try and except comes in same align. I will Show you one example :-
try:
– Open(fn)
except:
– print(‘file not found’)

(-) is space
This is one example I’m showing. I hope this would be helpful for you …!
Reply me If it’s would Helpfull for you…

1 Like

Hi @maazbobat3012
It is occuring because of indentation errror…

Try: and Except: should be indented properly. Like below example.

try:
    sensor_value = int(data['value'])
except e:
    print("There was an error while parsing the response: ",e)
    continue

Wrong Indentation looks like this

try:
    sensor_value = int(data['value'])

    except e:
    print("There was an error while parsing the response: ",e)    
    continue

I hope you found the difference, and problem is solved.