Сервер выдает ошибку 101
Написал небольшой сайт. При загрузке на хостинг выдает ошибку 101, при использовании на localhost ошибок нету. Что делать? ниже привожу код на python + Flask, хоть и не вижу нужды особой в этом.
from flask import Flask, render_template, request, redirect
import json
import os
import random
import smtplib as smtp
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
list1=[]
list2=[]
list1.append('testcod')
list2.append('email list')
def mail_send(target,text,header,reg_name,reg_pas):
cod = ''.join(random.choices("0123456789abcdefghijklmnopqrstuvwxyz", k=6))
list1.append(cod)
sender = ""
password = ""
msg = MIMEMultipart('alternative')
msg['Subject'] = header
msg['From'] = sender
msg['To'] = target
href = 'http://127.0.0.1:5000/search?'+'reg_name='+reg_name+'&email='+target+'®_pas='+reg_pas+'&code='+cod
# Create the body of the message (a plain-text and an HTML version).
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = f"""\<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body style="background: black;color: white;"><div style="position: relative;left: 50%;color: white;font-size: 20px;background: black;align-items: center;border-radius: 15px;min-width: 40%;max-width: 40%; margin-top: 2em; margin-bottom: 2em; margin:30%;"><div style="position: relative; width: 100%; height: 25px"></div><img style="position: relative; width: 100%;height: 275px;border-top-left-radius: 15px;border-top-right-radius: 15px;background: url('https://avatars.mds.yandex.net/i?id=474d71362f0c1ac1d9b4ec2056f459b0-5478714-images-thumbs&n=13');background-size:100% 100%;" src="https://lh3.google.com/u/0/d/1bym7t7ig_cidVhXXVvP3O4WAYEhngS6w=w300-h285-p-k-nu-iv1" class="img-height"><div style="padding: 1em;background: rgba(255, 255, 255, 0.1);">Приветствуем тебя<span style="color:red;"> {reg_name}</span>, для окончания регистрации перейди по ссылке: <a style="color:yellow; text-decoration: none;" href="{href}">ТЫК</span></div><div style="position: relative;width: 100%;background: rgba(255, 255, 255, 0.1);border-bottom-left-radius: inherit;border-bottom-right-radius: inherit;border-top: 5px dotted black;"><p style="text-align: center;">Присоединяйтесь к нам в соц сетях!</p><table style="margin-bottom: 1em;position: relative; left: 30%;"><tr><td><a style="text-decoration: none;" href="https://discord.gg/g9brzRVhRf"> <img style="width: 50px; height: 50px;" src="https://cdn.icon-icons.com/icons2/1945/PNG/512/iconfinder-discord-4661587_122459.png"></a></td><td><a style="text-decoration: none;" href="https://discord.gg/g9brzRVhRf"><div style=" color: #8C9EFF; margin-left: 5px; font-size: 25px;"> Discord </div></a></td></tr></table><div style="background:linear-gradient( 92.63deg , #769aff 8.23% , #ffdd40 25.83% , #f19994 51.91% , #47cf73 68.56% );position: relative;height:10px; width: inherit; border-bottom-left-radius: inherit;border-bottom-right-radius: inherit;"></div></div><div style="position: relative; width: 100%; height: 25px"></div></div></body></html>"""
part2 = MIMEText(html, 'html')
part1 = MIMEText(text, 'plain')
msg.attach(part1)
msg.attach(part2)
server = smtp.SMTP_SSL('smtp.yandex.com')
server.set_debuglevel(1)
server.ehlo(sender)
server.login(sender, password)
server.auth_plain()
server.sendmail(sender, target, msg.as_string())
server.quit()
app = Flask(__name__, template_folder=os.getcwd(), static_folder=os.getcwd())
@app.route("/", methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if request.form.get("register_name"):
register_name, email, register_password, repeat_password= request.form.values()
if register_password != repeat_password:
return render_template("index.html",type='2.1', log='Пароли не совпадают!', noreglog=register_name, nopas=register_password, nopas2=repeat_password, nomail=email)
with open("/home/Gsites2023/mysite/database.json", "r") as file:
data = json.load(file)
if data.get(register_name):
return render_template("index.html",type='2.2', log='Такой аккаунт уже существует!', noreglog=register_name, nopas=register_password, nopas2=repeat_password, nomail=email)
with open("/home/Gsites2023/mysite/database.json", "r") as file:
ma_list = file.read()
targ_mail = '"' + email + '"'
if targ_mail in ma_list:
return render_template("index.html",type='2.4', log='Данная почта уже привязана к другому аккаунту', noreglog=register_name, nopas=register_password, nopas2=repeat_password, nomail=email)
mail_send(email, 'some txt', 'Confirm registration',register_name,register_password)
return render_template("index.html",type='2.3', log='В почту отправлено письмо с инструкцией', newlog=register_name, newpas=register_password)
elif request.form.get("login"):
login, password = request.form.values()
with open("/home/Gsites2023/mysite/database.json", "r") as file:
data = json.load(file)
return render_template("index.html",type='1.1', log='Не зарегистрирован!', nolog=login, nopas=password)
if data.get(login) != password:
return render_template("index.html",type='1.2', log='Пароль неверный!', nolog=login, nopas=password)
return render_template("forum.html")
return render_template("index.html")
@app.route('/search', methods=['GET'])
def search():
args = request.args
code = args.get("code")
name = args.get("reg_name")
pas = args.get("reg_pas")
email = args.get("email")
if code in list1:
with ("/home/Gsites2023/mysite/database.json", "r") as file:
data = json.load(file)
data[name] = {"password":pas,"email":email,"role":"Player"}
with open("/home/Gsites2023/mysite/database.json", "w") as file:
json.dump(data, file)
list1.remove(code)
list2.append(email)
return redirect("https://gsites2023.pythonanywhere.com/")
return '''<h1>Код активации аккаунта не действительный. Попробуйте зарегестрироваться заново</h1><a style="text-decoration: none; text-align: center;" href="https://gsites2023.pythonanywhere.com/"><div style="text-decoration: none; color: white; margin:1em; background: #8C9EFF; padding:1em; cursor:pointer; border-radius:15vw; width: 10vw; test-align: center;">На главную</div></a>'''
при верной форме и нажатии на кнопку регистрации выдает такую ошибку
2022-09-18 16:26:24,298: Exception on / [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2051, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1501, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1499, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1485, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/home/Gsites2023/mysite/flask_app.py", line 67, in index
mail_send(email, 'some txt', 'Confirm registration',register_name,register_password)
File "/home/Gsites2023/mysite/flask_app.py", line 39, in mail_send
server = smtp.SMTP_SSL('smtp.yandex.com')
File "/usr/lib/python3.8/smtplib.py", line 1034, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/usr/lib/python3.8/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.8/smtplib.py", line 339, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.8/smtplib.py", line 1040, in _get_socket
new_socket = socket.create_connection((host, port), timeout,
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable