我试图将用户添加到数据库中,但遇到此错误:
[08/Oct/2018 14:18:01] - [O M N I A] Updated online for user: Майор пейн
[08/Oct/2018 14:18:01] - [O M N I A] Updated online for user: Nikodus
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/root/bot/botevents.py", line 48, in counter
db_cursor.execute("INSERT INTO `users` (`server_id`, `user_name`, `user_id`, `last_update_online`, `last_update`) VALUES ('{0}', '{1}', '{2}', {3}, {3})".format(server.id, member.name.replace("'", ''), member.id, time.time()))
File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 170, in execute
result = self._query(query)
File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 328, in _query
conn.query(q)
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 516, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 727, in _read_query_result
result.read()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 1066, in read
first_packet = self.connection._read_packet()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 683, in _read_packet
packet.check_error()
File "/usr/local/lib/python3.5/dist-packages/pymysql/protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python3.5/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '397911167944622100', 1539008281.6296663, 1539008281.6296663)' at line 1")
它添加了一些用户,但是一会儿卡住并得到该错误。 可能是bcz是7k用户,而我的VDS只有一个核心和两个ram?
import pymysql, time, discord
from datetime import datetime
import warnings
warnings.simplefilter("ignore")
class BotEvents:
def __init__(self, *args, **kwargs):
@self.bot.event
async def on_ready():
self.log('\n', save=True)
self.log('-----------------------------------------', save=True)
self.log('Authorize successfully', save=True)
self.log('Authorized servers: ', save=True)
[self.log(' Name (id): %s (%s)' % (info.name, info.id), save=True) for info in self.bot.guilds]
self.log('-----------------------------------------', save=True)
await self.bot.loop.create_task(self.female_logic())
def counter(self, server):
db_conn, db_cursor = self.connect_db()
result = db_cursor.execute("SELECT `user_id` FROM `users` WHERE server_id = '{}'".format(server.id))
members = []
if result != 0:
for x in range(result):
members.append(db_cursor.fetchone()[0])
db_conn.close()
while self.run_c:
roles = []
member_role = []
db_conn, db_cursor = self.connect_db()
result = db_cursor.execute("SELECT `role_id`, `min_exp` FROM `auto_roles` WHERE server_id = '{}' ORDER BY `min_exp`".format(server.id))
if result != 0:
info = db_cursor.fetchone()
member_role = [str(info[0]), int(info[1])]
for x in range(result - 1):
info = db_cursor.fetchone()
roles.append([str(info[0]), int(info[1])])
db_conn.close()
for member in server.members:
if member != self.bot.user:
db_conn, db_cursor = self.connect_db()
if str(member.id) not in members:
db_cursor.execute("INSERT INTO `users` (`server_id`, `user_name`, `user_id`, `last_update_online`, `last_update`) VALUES ('{0}', '{1}', '{2}', {3}, {3})".format(server.id, member.name.replace("'", ''), member.id, time.time()))
db_conn.commit()
members.append(str(member.id))
self.log(' [%s] Added user: %s' % (server.name, member.name), save=True)
else:
db_cursor.execute("SELECT `member`, `balance`, `online_time`, `last_update_online`, `experience`, `last_update`, `autorole` FROM `users` WHERE (user_id = '{}' AND server_id = '{}')".format(member.id, server.id))
info = db_cursor.fetchone()
if info is not None:
info = {
'member':bool(info[0]),
'balance':int(info[1]),
'online_time':int(info[2]),
'last_update_online':int(info[3]),
'experience':int(info[4]),
'last_update':int(info[5]),
'autorole':info[6]
}
if int(time.time()) - info['last_update_online'] > 60:
if str(member.status) in ['online', 'idle', 'dnd']:
db_cursor.execute("UPDATE `users` SET online_time = {}, last_update_online = {} WHERE (user_id = '{}' AND server_id = '{}')".format(
info['online_time'] + 1,
time.time(),
member.id,
server.id))
db_conn.commit()
self.log('[%s] Updated online for user: %s ' % (server.name, member.name), save=True)
if int(time.time()) - info['last_update'] > 60:
if member.voice is not None:
db_cursor.execute("UPDATE `users` SET balance = {}, experience = {}, last_update = {} WHERE (user_id = '{}' AND server_id = '{}')".format(
info['balance'] + self.gold_per_minut,
info['experience'] + self.exp_per_minut,
time.time(),
member.id,
server.id))
db_conn.commit()
self.log('[%s] Updated balance, experience for user: %s ' % (server.name, member.name), save=True)
if len(member_role) != 0:
if not info['member'] and info['experience'] >= member_role[1]:
role_o = discord.utils.get(server.roles, id=int(member_role[0]))
if role_o not in member.roles:
self.bot.loop.create_task(member.add_roles(role_o))
db_cursor.execute("UPDATE `users` SET member = {} WHERE (user_id = '{}' AND server_id = '{}')".format(True, member.id, server.id))
db_conn.commit()
new_role = ''
for role in roles:
if role[1] <= info['experience']:
new_role = role[0]
if new_role != '' and new_role != info['autorole']:
if info['autorole'] != '0':
role_o = discord.utils.get(server.roles, id=int(info['autorole']))
if role_o in member.roles:
self.bot.loop.create_task(member.remove_roles(role_o))
self.log('[%s] For user %s deleted old role %s(%s)' % (
server.name,
member.name,
role_o.name,
role_o.id) , save=True)
time.sleep(2)
role_o = discord.utils.get(server.roles, id=int(new_role))
if role_o is not None:
if role_o not in member.roles:
db_cursor.execute("UPDATE `users` SET autorole = '{}' WHERE (user_id = '{}' AND server_id = '{}')".format(new_role, member.id, server.id))
db_conn.commit()
self.bot.loop.create_task(member.add_roles(role_o))
self.log('[%s] For user %s added role %s(%s)' % (server.name, member.name, role_o.name, role_o.id), save=True)
db_conn.close()
有人知道该如何解决? botevents.py文件出现此错误: https://pastebin.com/UdMhDrMh
@Suresh,添加引号后完成错误:
[08/Oct/2018 16:37:33] - [O M N I A] Added user: Shein
[08/Oct/2018 16:37:33] - [O M N I A] Added user: ара
[08/Oct/2018 16:37:34] - [O M N I A] Added user: ROFLANOV
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/root/bot/botevents.py", line 48, in counter
db_cursor.execute("INSERT INTO `users` (`server_id`, `user_name`, `user_id`, `last_update_online`, `last_update`) VALUES ('{0}', '{1}', '{2}', '{3}', '{3}')".format(server.id, member.name.replace("'", ''), member.id, time.time()))
File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 170, in execute
result = self._query(query)
File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 328, in _query
conn.query(q)
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 516, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 727, in _read_query_result
result.read()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 1066, in read
first_packet = self.connection._read_packet()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 683, in _read_packet
packet.check_error()
File "/usr/local/lib/python3.5/dist-packages/pymysql/protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python3.5/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '397911167944622100', '1539016654.7659388', '1539016654.7659388')' at line 1")
答案 0 :(得分:0)
插入数据时,您需要将时间值括在单引号中。 请使用以下代码:
sonar.host.url=$SONAR_HOST_URL
sonar.login=$SONAR_AUTH_TOKEN
sonar.sources=src/main
sonar.projectBaseDir=../
sonar.jacoco.reportPaths=**/target/jacoco-it.exec
希望这行得通!