Socket-python syntax error

Asked

Viewed 167 times

0

  except socket.error, (errno, msg):
            if errno == 1:
                # Operation not permitted
                msg = msg + (
                    " - Note that ICMP messages can only be sent from processes"
                    " running as root."
                )
                raise socket.error(msg)

Traceback (Most recent call last):

File "", line 1, in File "/usr/lib/python3/dist-Packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile execfile(filename, namespace) File "/usr/lib/python3/dist-Packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile exec(Compile(open(filename, 'Rb').read(), filename, 'exec'), namespace) File "/home/epamos/Downloads/Gping2(1). py", line 78 except socket.error, (Errno, msg): Syntaxerror: invalid syntax

I am using python 3.5, when removing the comma there is the triggering of 7 errors involving Gping.

  • 1

    Post the full stack trace. You can add it by clicking edit.

  • And if you do except socket.error as err: then you should adjust. I’m on the tele and I can’t test but it might solve

  • Unfortunately it didn’t solve the problem!

1 answer

2

This Except syntax is not valid in Python 3- this is the old Python 2 syntax, and even in new code made to run in Python 2 it is still recommended to use the new style:

try:
   ...
except NomeDoErro as variavel:
   ...

In that case:

except socket.error as error:
    # codigo usando a variável error

(Note, I suggest you arrange the indentation of your Python code to use 4 spaces per block, always - and not varied indentation - you will notice that it is much easier to read)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.