Fix Socket.Gaierror: [Errno 8] Nodename Nor Servname Provided, or Not Known in Python
parent
6a17f4a239
commit
9d51c6d8f3
14
settings.py
14
settings.py
|
@ -32,9 +32,7 @@ warnings.simplefilter('ignore',InsecureRequestWarning)
|
|||
import ssl
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
|
||||
import socket
|
||||
|
||||
CONST_APP_VERSION = "MaxBot (2023.07.01)"
|
||||
CONST_APP_VERSION = "MaxBot (2023.07.02)"
|
||||
|
||||
CONST_MAXBOT_CONFIG_FILE = "settings.json"
|
||||
CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt"
|
||||
|
@ -495,10 +493,20 @@ def load_translate():
|
|||
return translate
|
||||
|
||||
def get_ip_address():
|
||||
default_ip = "127.0.0.1"
|
||||
ip = default_ip
|
||||
try:
|
||||
ip = [l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
|
||||
if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)),
|
||||
s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET,
|
||||
socket.SOCK_DGRAM)]][0][1]]) if l][0][0]
|
||||
except Exception as exc:
|
||||
print(exc)
|
||||
try:
|
||||
ip = socket.gethostname()
|
||||
except Exception as exc2:
|
||||
print(exc2)
|
||||
ip = default_ip
|
||||
return ip
|
||||
|
||||
def format_config_keyword_for_json(user_input):
|
||||
|
|
Loading…
Reference in New Issue