AttributeError: 'socket' object has no attribute 'connect_exp'


Beginner python proggammer here. Thank you for your help!

Please post your questions as text rather than screenshots.

As far as I can tell, you get an AttributeError because the socket object does not have a connect_exp method. It does have a connect_ex method, though :slight_smile:

1 Like

Welcome, @design !

@zware already answered the “what” specific question, but it is helpful to understand the “how” of solving it for the future—as programmers, like to not just solve specific problems, but rather whole classes of ones. To that end, when you see a Python error traceback in the future, you can often solve in yourself—it takes a little getting used to at first, but the only way to do that is try it!

To do so, you should examine the traceback carefully and in full. First, look at the error message—what’s it saying? Here, you have an AttributeError, which is raised when an attribute of an object (which includes methods) is requested (via . or getattr) and it does not exist. Specifically, the error message tells you that you are attempting to access an attribute connect_exp on some instance of the socket class, which does not have such an attribute.

Especially in beginner code, this usually boils down to a few related root causes, which are good to keep in mind—either objects of that class do not have an attribute you thought it did (check its documentation), the attribute name was simply mispelled (ditto), the object isn’t the class you thought it was (ditto, and check that the class name matches what you expect), or you’re not accessing the attribute on the right object (ditto, ditto, and trace your code carefully).

Now, let’s look at the rest of the traceback. In particular, you’ll usually want to start at the last line (from the top) that refers to a file in your own code, and see which of those problems could potentially apply to it. In this case, there’s only one line in the traceback, your code s.connect_exp(...). Although your variable s is rather cryptically named with a single letter (try to use more descriptive, unique variable names), one can presume it is a socket object, or at least intended to be, and the method connect_exp is attempted to be called on it—which is exactly what your error message is telling you doesn’t exist. So, you can check the documentation for socket objects, and notice that there is a connect_ex method—problem solved!

And of course, if you still can’t figure it out, almost any problem you are likely to run into as a beginner has been found and solved by someone before, so searching for it online is very likely to get an answer much faster with less effort than asking others on a forum.

FWIW, just to echo, please don’t post screenshots of text. Instead, include a minimal reproducible example and the complete traceback and error message inside code block(s), like this:


(Or use the </> button on the toolbar to insert a code block).

Best of luck!

1 Like

Thank you so much! I appreciate your guidance. I have alot to learn but I’ll get there!

1 Like