Answer the question
In order to leave comments, you need to log in
AttributeError: 'NoneType' object has no attribute 'close'?
I wrote a simple program related to MySQL database and VC, "user registration".
Here is the code:
import pymysql.cursors
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from plugins import system
import random
import time
import re
from datetime import datetime, timedelta
def connection():
connection = pymysql.connect(host='localhost', user='root', password='root', db='testbase', cursorclass=pymysql.cursors.DictCursor)
def register(user_id):
connect = connection()
try:
with connect.cursor() as cursor:
result = cursor.execute(f'SELECT * FROM accounts WHERE uid={user_id}')
if result == 0:
cursor.execute(f'INSERT INTO accounts(uid) VALUES({user_id})')
connect.commit()
return 'Вы успешно зарегистрировались'
else:
return 'Вы уже зарегистрированны'
finally:
connect.close()
rand = random.randint(-2147483648, 2147483648)
vk_session, vk, longpoll = system.session()
print('logged')
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
message = event.obj.text
if message == 'register':
text = function.register(event.obj.from_id)
vk.messages.send(peer_id=event.obj.peer_id, random_id=rand, message={text})
Answer the question
In order to leave comments, you need to log in
In procedure
you return
nothing It is nothing you assign connect and try to pull its nonexistent methods. Here is the error and gives you
def connection():
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question