How to Solve Error: socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Situation 1:
Error content:
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Reason:
hostname is not written in /etc/hosts. For example, the MAC-20150101 in the abnormal information above is actually the host name of our Mac system. Some codes may need to find the corresponding IP address in the local DNS according to the host name, because the local DNS configuration is not specified What is the IP address of the host name, this error will also be prompted.
Solution:
Implement in python interpreter:
python
Call the gethostname() method provided by the Socket library to obtain the host name
>>>import socket >>>socket.gethostname() >>>>exit()
Get the host name, modify the hosts file, enter the command
vim /etc/hosts
Add the host name 127.0.0.1 hostname
Error resolution
Situation 2:
The solution to prompt nodename nor servname provided when the Java Web project is started on the Mac system
java.net.UnknownHostException: MAC-20150101: MAC-20150101: nodename nor servname provided, or not known at java.net.InetAddress.getLocalHost(InetAddress.java:1473) at org.eclipse.rse.core.RSECorePlugin.getLocalMachineName(RSECorePlugin.java:265) at org.eclipse.rse.core.RSEPreferencesManager.getDefaultPrivateSystemProfileName(RSEPreferencesManager.java:358) at org.eclipse.rse.core.RSEPreferencesManager.initDefaults(RSEPreferencesManager.java:337) at org.eclipse.rse.internal.core.RSEPreferenceInitializer.initializeDefaultPreferences(RSEPreferenceInitializer.java:23) at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper$1.run(PreferenceServiceRegistryHelper.java:300) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) .... .... .... Caused by: java.net.UnknownHostException: MAC-20150101: nodename nor servname provided, or not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293) at java.net.InetAddress.getLocalHost(InetAddress.java:1469) ... 28 more
Regarding the MAC-20150101 in the exception information, it is actually the host name of our Mac system. Some codes may need to find the corresponding IP address in the local DNS according to the host name, because the local DNS configuration does not specify the host What is the name of this IP address, this error will also be prompted.
The solution is very simple:
1) Open the terminal on the Mac system, check the current host DNS configuration, enter the command cat /private/etc/hosts, as shown in the figure:
2) Then edit the host configuration, add the mapping of the host name, enter the command sudo vi /private/etc/hosts, enter the VI editor, and add the following mapping
127.0.0.1 MAC-20150101
Just exit and save.
3) Finally, enter the refresh command dscacheutil -flushcache in the terminal
After three steps, when starting the Java Web project, the following error message will not appear.
The reason for this error is that the Internet says that there is a place in the project that calls the following code:
InetAddress.getLocalHost().getCanonicalHostName();
It is said that this method will return FQDN (Fully Qualified Domain Name), if the host name is not configured, then calling this code will throw an exception message, and this method depends on the underlying operating system, the configuration of the Mac system is somewhat different from that of Windows !
Situation 3:
Socket.gaierror: [Errno -2] Name or service not known error solution when configuring the remote server Jupyter notebook
Modify the jupyter_notebook_config.py configuration file and enter the command:
vim ~/.jupyter/jupyter_notebook_config.py
In the configuration file, search for c.NotebookApp.ip, find this sentence and modify it to c.NotebookApp.ip=’0.0.0.0′ (general tutorial will write and modify it to’*’), save and restart the notebook.
## The IP address the notebook server will listen on. c.NotebookApp.ip = '*' c.NotebookApp.allow_remote_access=True
Read More:
- [Errno 8] nodename nor servname provided, or not known
- In windows, “cmake” is not an internal or external command, nor a runnable program or batch file.
- Ant Design ‘cross env’ is not an internal or external command, nor is it an error reporting problem for a runnable program
- Jstack command execution error: unable to open socket file: target process not responding or hotspot VM not loaded
- Error “/run/lvm/lvmetad.socket: connect failed: No such file or directory” – but not Grub related
- Neither –kubeconfig nor –master was specified. Using the inClusterConfig. This might not work
- Failed to restart xxx.service: The name org.freedesktop.PolicyKit1 was not provided by any..
- gazebo7 CMake Error:Could not find a package configuration file provided by “gazebo_plugins“
- What should be paid attention to in socket programming — bind socket error: address already in use
- Consult IDE log for more details (Help | Show Log),read failed, socket might closed or timeout,
- ERROR 1524 (HY000): Plugin ‘auth_socket’ is not loaded How to Fix
- java.net.SocketException: socket failed: EPERM (Operation not permitted)
- Could not sync socket: %1
- Error in installing torch vision or pilot on Linux or Jetson nano: the headers or library files could not be found for JPEG
- [robot_launch.launch] is neither a launch file in package [kinova_gazebo] nor is
- Failed to connect to Mir:Failed to connect to server socket:No such file or directory
- The media could not be loaded, either because the server or network failed or because the format is
- Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://xxx.cn’) does n
- Problems encountered after Maven installation or upgrade: could not find or load main class org.codehaus.plexus .class…..
- INFO Starting development server…. ERROR Error: Rule can only have one resource source (provided