AF_INET error

Fredrik Lundh effbot at telia.com
Tue Apr 11 15:06:07 EDT 2000


Soundwave <maybe at lucky.com> wrote:
> import socket
> #create an INET, STREAMing socket
> s = socket.socket(
>     socket.AF_INET, socket.SOCK_STREAM)
> #now connect to the web server on port 80
> # - the normal http port
> s.connect("www.mcmillan-inc.com", 80)
>
> when I run this code, I get the following output
>
> Traceback (innermost last):
>   File "C:\PROGRA~1\PYTHON\TOOLS\IDLE\ScriptBinding.py", line 131, in
> run_module_event
>     execfile(filename, mod.__dict__)
>   File "C:/Program Files/Python/socket.py", line 3, in ?
>     s = socket.socket(
> AttributeError: AF_INET

hmm.  this example works just fine on my windows 95 box,
running it from the command line prompt.

maybe IDLE is interfering with your code in some strange
way?  here are a few things you might wish to try:

-- restart IDLE, and try running the script again

-- try running it from an MS-DOS window

-- try adding the following two statements just after
   the import statement:

        print socket
        print dir(socket)

this should print something like:

<module 'socket' from 'C:\program~1\python\lib\plat-win\socket.pyc'>
>>> print dir(socket)
['AF_INET', 'INADDR_ALLHOSTS_GROUP', 'INADDR_ANY', ...lots of
other stuff... 'htons', 'ntohl', 'ntohs', 'socket']

</F>





More information about the Python-list mailing list