unsupported operand type(s) for *: 'NoneType' and 'int'
Нужна помощь! Есть проект, TermNet, в нём есть две основные функции, на которых по сути и держится весь код, это функции authorization() (авторизация) и registration() (регистрация). Так вот, в обеих функциях есть три основные переменные: login, password, netkey. Последняя является неким ip-адресом внутри моей локальной сети TermNet-а. В чём суть: при регистрации логин и пароль пользователь придумывает сам, а вот ключ надо генерировать. Ключ выглядит так: 1234:1234:1234:1234, - это 16-тизначное число, разделённое символом ":" через каждую секцию, состоящую из 4-ёх цифр. Я пробовал следующий код:
def genrannetkey():
a = print(random.randint(1, 9))
a = a * 4
genrannetkey()
Всё взаимодействие с кодом и генерацией происходит через встроенный модуль питона random.
кто-нибудь, напишите, пожалуйста, код, который будет случайно генерировать такой ключ, как у меня в примере. Гайды на ютубе по модулю рандом не особо помогают, в интернете помощи тоже особо нет, поэтому обратился.
Вот весь код, на данный момент:
# python 3.7.4 Official Release.
from tqdm import tqdm, tqdm_gui, trange
import pyautogui
import time
import os
def loadbarTermNet():
for i in trange(100, desc="Connecting...", unit="termcon"):
time.sleep(0.3)
def registration():
loginreg = input("Entry a new login: ")
passreg = input("Entry a new password: ")
def authorization():
print("Authorization in TermNet.")
login = input("Login: ")
password = input("Password: ")
netkey = input("Net Key: ")
if login == "status1.t3rm":
if password == "ilisium.is.t3rmc0d3":
if netkey == "":
print("Authorization is successfully!")
loadbarTermNet()
else:
print("New to TermNet? Register now!")
question = input("New to TermNet, wanted to registy?: ")
if question.lower()[:1] == "y":
registration()
else:
print("Then what at is incorrect a data, please retry a attempt.")
authorization()
else:
print("New to TermNet? Register now!")
question = input("New to TermNet, wanted to registy?: ")
if question.lower()[:1] == "y":
registration()
else:
print("Then what at is incorrect a data, please retry a attempt.")
authorization()
else:
print("New to TermNet? Register now!")
question = input("New to TermNet, wanted to registy?: ")
if question.lower()[:1] == "y":
registration()
else:
print("Then what at is incorrect a data, please retry a attempt.")
authorization()
Обращаюсь к тебе уважаемый @uw935.
Тут возникла проблема. В основном проекте, если пройти авторизацию, всё работает правильно и корректно, но вот с регистрацией возникли проблемы. Отдельно, твой код работает, а вот когда я его интегрировал его в свой код, и соответственно адаптировал его под себя, и под основной код проекта, питон выдал ошибку.
Тест отдельно. Код:
from tqdm import tqdm, tqdm_gui, trange
import time
import random
# a = random.randint(1000, 9999)
# b = random.randint(1000, 9999)
# c = random.randint(1000, 9999)
# d = random.randint(1000, 9999)
#
# print(a, b, c, d, sep=":")
loginreg = input("Entry a new login: ")
passreg = input("Entry a new password: ")
for i in trange(100, desc="Generating random network key(netkey)..."):
time.sleep(0.2)
a = random.randint(1000, 9999)
b = random.randint(1000, 9999)
c = random.randint(1000, 9999)
d = random.randint(1000, 9999)
randnetkey = print(a, b, c, d, sep=":")
Результат:
D:\Terminalius\TermNet\$cash>test-random.py
Entry a new login: a
Entry a new password: a
Generating random network key(netkey)...: 100%|██████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:20<00:00, 4.83it/s]
5486:3515:3080:7937
Тест в проекте. Код:
# python 3.7.4 Official Release.
from tqdm import tqdm, tqdm_gui, trange
import pyautogui
import time
import os
login = "status1.t3rm"
def genrandnetkey():
a = random.randint(1000, 9999)
b = random.randint(1000, 9999)
c = random.randint(1000, 9999)
d = random.randint(1000, 9999)
print(a, b, c, d, sep=":")
def termnet():
msgbox = input("Input the message: ")
sendmsg = input("Send?[Y/N]> ")
if sendmsg == "Y" or sendmsg == "y":
print(login + ":" + " " + msgbox + "\n")
else:
print("Empty message is cannot a sending!")
def loadbarTermNet():
for i in trange(100, desc="Connecting...", unit="termcon"):
time.sleep(0.3)
termnet()
def authorization():
print("Authorization in TermNet.")
login = input("Login: ")
password = input("Password: ")
netkey = input("Net Key: ")
if login == "status1.t3rm":
if password == "ilisium.is.t3rmc0d3":
if netkey == "2020:0208:8080:0808":
print("Authorization is successfully!")
loadbarTermNet()
else:
print("New to TermNet? Register now!")
question = input("New to TermNet, wanted to registy?: ")
if question.lower()[:1] == "y":
registration()
else:
print("Then what at is incorrect a data, please retry a attempt.")
authorization()
else:
print("New to TermNet? Register now!")
question = input("New to TermNet, wanted to registy?: ")
if question.lower()[:1] == "y":
registration()
else:
print("Then what at is incorrect a data, please retry a attempt.")
authorization()
else:
print("New to TermNet? Register now!")
question = input("New to TermNet, wanted to registy?: ")
if question.lower()[:1] == "y":
registration()
else:
print("Then what at is incorrect a data, please retry a attempt.")
authorization()
def registration():
loginreg = input("Entry a new login: ")
passreg = input("Entry a new password: ")
for i in trange(100, desc="Generating random network key(netkey)..."):
time.sleep(0.3)
a = random.randint(1000, 9999)
b = random.randint(1000, 9999)
c = random.randint(1000, 9999)
d = random.randint(1000, 9999)
randnetkey = print(a, b, c, d, sep=":")
with open("datastorage.dat", 'a') as savedata:
savedata.write(login + "\n")
savedata.write(passreg + "\n")
savedata.write(randnetkey + "\n")
print("Copying it network key for the next of Authorization!")
print("Do you a have the 10 second.")
time.sleep(10.0)
authorization()
authorization()
Результат:
D:\Terminalius\TermNet>main.py
Authorization in TermNet.
Login: a
Password: a
Net Key: a
New to TermNet? Register now!
New to TermNet, wanted to registy?: y
Entry a new login: hell-o
Entry a new password: 123456
Generating random network key(netkey)...: 100%|██████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:30<00:00, 3.26it/s]
Traceback (most recent call last):
File "D:\Terminalius\TermNet\main.py", line 83, in <module>
authorization()
File "D:\Terminalius\TermNet\main.py", line 59, in authorization
registration()
File "D:\Terminalius\TermNet\main.py", line 69, in registration
a = random.randint(1000, 9999)
NameError: name 'random' is not defined
Ответы (1 шт):
Добрый вечер.
Если я правильно конечно понял.) Если что то не так - пишите.
Решил попробовать сделать, то, что вы написали и у меня получился такой код:
import random
a = random.randint(1, 1455)
b = random.randint(1, 1455)
c = random.randint(1, 1455)
d = random.randint(1, 1455)
print(a, b, c, d, sep=":")
Конечно, что заместо чисел которые у меня указаны в randint(1, 1455) можно поставить что угодно.