0

code

import socket
line = 'http://www.permobil.com/en/Corporate/'
IP = socket.gethostbyname(line)

error

IP = socket.gethostbyname(line)
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

I know there are several answers for the same error, but none helped i looked 1 2 while others answers were not applicable.

3
  • Have you tried: stackoverflow.com/a/2805413/3649209 Commented Jun 23, 2016 at 10:26
  • Other questions: Have you tried it with a well known domain name like google.com, does it work for that domain? Are you behind a corporate proxy? Are you sure the DNS server for permobil.com are set up correctly? Are you using unix? If so, does the unix DNS lookup command: host permobil.com give an IP address successfully from your location? Commented Jun 23, 2016 at 10:30
  • it works for all the domains with base URL like google.com, permobil.com Commented Jun 23, 2016 at 10:51

2 Answers 2

0

try this:

import socket

ip = socket.gethostbyname("permobil.com")
print ip
Sign up to request clarification or add additional context in comments.

5 Comments

i already know that this works, but can i get the base URL for a website
which would be permobil.com in our case
I don't understand? All you need to do is to parse your string and get right part
but if i have tons of such websites to parse in a json file, would i be manually removing http n all that stuff to make my string permobil.com
write function that does that for you, dont forget about https too, and then pass it to socket function, there is no other way
0
import socket
from urlparse import urlparse

parsed_uri = urlparse('http://www.permobil.com/en/Corporate/' )
domain = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
domain = domain.replace("http://","")
domain = domain.replace("www.", "")
domain = domain.replace("/", "")
IP = socket.gethostbyname(domain)

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.