0

I have the following code in order to create a socket:

#!/usr/bin/python

import socket
import sys

try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
        print 'Failed to create socket. Error code: ' + str(msg[0]) + ' Error message: ' + msg[1]
        sys.exit();
print 'Socket created!'

but I have the following error:

AttributeError: 'module' object has no attribute 'error'
3
  • You have an error in except statement Commented May 16, 2014 at 14:08
  • @frostnational: true, but that's not the cause of the exception here. Commented May 16, 2014 at 14:08
  • I don't know how to solve it? I am new with python really..thank you Commented May 16, 2014 at 14:08

2 Answers 2

2

You have a different module named socket on your path. You did not import the stdlib module because it is being masked.

Print out the filename of the masking module to locate it, then rename it:

print socket.__file__
Sign up to request clarification or add additional context in comments.

Comments

0

Check out your python's file name, don't use the file name that are same with python's module (e.g socket.py, etc)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.