'it failed when tried to get host name using python

socket.getfqdn() 

and the result is ok,return sjs_88_78 and then

socket.gethostbyname('sjs_88_78')

it will socket.gaierror: [Errno -2] Name or service not known is it env issue?how to fix it?

BTW,i run on Red Hat Enterprise Linux Server release 6.6 (Santiago)



Solution 1:[1]

Is it possible that there are some wrong characters in the name in the second command?

gaierror stands for "getadressinfo error". I saw this error in a case when I had some wrong character in my hostname. In my case that was an additional space that I wrongly copied and paste... Not sure that it's your case as well... but just for information.

Also, it's interesting if a invisible return character could provoke this. Like difference between Unix and Windows return character...

Solution 2:[2]

It could be that you don't have a proper address-to-host mapping set up on your server. From the Python socket docs:

"If you want to know the current machine’s IP address, you may want to use gethostbyname(gethostname()). This operation assumes that there is a valid address-to-host mapping for the host, and the assumption does not always hold."

https://docs.python.org/2/library/socket.html#socket.gethostname

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul Zakharov
Solution 2 Andrew Guy