Home > database >  IndentationError: expected an indented block after 'if' statement on line 32
IndentationError: expected an indented block after 'if' statement on line 32

Time:06-20

The erro points to line 34 where finally is, but I tried to reorganize it in many different positions and it insists that the indentation is incorrect. Though as far as I learn the try, except and finally block should be aligned together. Can anyone help me figured out what the hell it wants from me??

                                try:
                                    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                                    sock.connect(('10.0.2.15', 666))
                                    while True:
                                        data = sock.recv(1024)
                                        url = data[:data.find('|')]
                                except:
                                       if url.count("/") == 2:
                                    
                                finally:

CodePudding user response:

The error is actually the lack of a statement suite on line 33, after the if statement on line 32. The omission is detected on line 34 because line 33 is blank and finally: is not the required statement or block of statements. The finally: itself would be fine if it also were followed by a suite.

except:
    if url.count("/") == 2:
        # You need a statement suite here!!!
finally:

CodePudding user response:

If you used spaces mixed with tabs it will cause this error.

  • Related