Socket Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kingofearth.com@gmail.com

    Socket Error

    When I try to open a socket with python i get the following error:

    Traceback (most recent call last):
    File "./mailer", line 3, in ?
    sock = socket.socket(s ocket.PF_INET, socket.SOCK_STR EAM)
    NameError: name 'socket' is not defined

    the code is:

    #!/usr/bin/python

    sock = socket.socket(s ocket.PF_INET, socket.SOCK_STR EAM)
    sock.connect((" mail.oasd.k12.w i.us", 25))
    sock.send("HELO ")
    print sock.recv(8192)
    sock.close()

  • Tiziano Bettio

    #2
    Re: Socket Error

    kingofearth.com @gmail.com wrote:
    [color=blue]
    >When I try to open a socket with python i get the following error:
    >
    >Traceback (most recent call last):
    > File "./mailer", line 3, in ?
    > sock = socket.socket(s ocket.PF_INET, socket.SOCK_STR EAM)
    >NameError: name 'socket' is not defined
    >
    >the code is:
    >
    >#!/usr/bin/python
    >
    >sock = socket.socket(s ocket.PF_INET, socket.SOCK_STR EAM)
    >sock.connect(( "mail.oasd.k12. wi.us", 25))
    >sock.send("HEL O")
    >print sock.recv(8192)
    >sock.close()
    >
    >
    >[/color]
    tried:
    import socket
    ???

    Comment

    • wittempj@hotmail.com

      #3
      Re: Socket Error

      You missed the import socket statement. Also the socket.PF_INET should
      be socket.AF_INET

      Comment

      • Achim Domma (Procoders)

        #4
        Re: Socket Error

        kingofearth.com @gmail.com wrote:
        [color=blue]
        > NameError: name 'socket' is not defined[/color]

        You forgot to import the socket module:

        import socket

        regards,
        Achim

        Comment

        • kingofearth.com@gmail.com

          #5
          Re: Socket Error

          Thanks everybody, it works now. I thought I needed to do something like
          that but it didn't show it in the tutorial so I decided to ask here.

          Comment

          • Matt

            #6
            Re: Socket Error


            kingofearth.... @gmail.com wrote:[color=blue]
            > Thanks everybody, it works now. I thought I needed to do something[/color]
            like[color=blue]
            > that but it didn't show it in the tutorial so I decided to ask here.[/color]

            Where was the tutorial? If it's in the Python docs, perhaps you could
            submit a patch to fix it ... ;-)

            M@

            Comment

            Working...