-2

I'm testing the Socket module by writing some very simple code, but I'm having an error!

Follow the code below:

import socket

resp="Y"
while(resp=="Y"):
    url=input("URL: ")
    ip=socket.gethostbyname(url)
    print("IP: ", ip)
    resp=input("Type <y> to continue: ").upper()

Error Image

MendelG
  • 14,885
  • 4
  • 25
  • 52

1 Answers1

6

You probably named your file socket.py, if you did so, change it and try again.

In principle, always post the entire traceback

Jonathan1609
  • 1,809
  • 1
  • 5
  • 22
  • 2
    Hey. This answer should have been a comment (as @DeepSpace did). Please see [When should I answer and when should I comment?](https://meta.stackoverflow.com/questions/366515/when-should-i-answer-and-when-should-i-comment) – MendelG Jun 30 '21 at 20:36
  • @MendelG That is kind of funny because I doubted whether to post it as a comment or as an answer, but eventually I decided to post it as an answer since it is really an answer, he most likely named his file socket.py and that is the answer, to change the filename. if the probability that that's his issue was low, I wouldn't post it as an answer :D. BTW Thanks for the comment, I'll consider it more seriously next time. – Jonathan1609 Jun 30 '21 at 20:38
  • 1
    No worries, I just noticed that you are a recent user of the site. So I was just trying to help – MendelG Jun 30 '21 at 20:40
  • 1
    I changed the filename and it worked! Thanks a lot for the help – Anderson Peruci Jun 30 '21 at 21:00
  • 2
    The right course of action here is to search to see if this (common) issue has been asked about on stackoverflow before. If you find a previous occurrence, _flag_ this question as a duplicate. – snakecharmerb Jun 30 '21 at 23:25