您好,在我的代码中它破坏了我的请求,我尝试了几次,但是1-2小时后,僵尸状态不再更改。
我将这些文件托管在ftp服务器中。
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from discord import Game
import math, time
import requests
Client = discord.client
client = commands.Bot(command_prefix = '!')
Clientdiscord = discord.Client()
@client.event
async def on_ready():
client.loop.create_task(scheduler())
print('project ready')
async def scheduler():
while True:
# sleep until the next whole second
now = time.time()
await asyncio.sleep(math.ceil(now) - now)
await client.change_presence(game=discord.Game(name='steady', type=3))
await asyncio.sleep(5)
await client.change_presence(game=discord.Game(name='ready', type=3))
await asyncio.sleep(5)
await client.change_presence(game=discord.Game(name='go', type=3))
await asyncio.sleep(5)
await client.change_presence(game=discord.Game(name='Total Used : '+requests.get('http://username.mydomain/project/total_visit/count.txt').text, type=3))
await asyncio.sleep(10)
await client.change_presence(game=discord.Game(name='Online : '+requests.get('http://username.mydomain/project/total_online/Live.php').text, type=3))
await asyncio.sleep(10)
await client.change_presence(game=discord.Game(name='Total Users : '+requests.get('http://username.mydomain/project/total_users/total.php').text, type=3))
await asyncio.sleep(10)
await client.change_presence(game=discord.Game(name='return again', type=3))
#i tired to kill all request to start clear again.
client.logout()
client.close()
await asyncio.sleep(20)
client.run("client_token")
从未检索到任务异常 未来:exception = ConnectionError(MaxRetryError(“ HTTPConnectionPool(host ='username.mydomain',port = 80):url超过最大重试次数:/project/total_visit/count.txt(由NewConnectionError(':导致无法建立新的连接:[WinError 10061]无法建立连接,因为目标计算机主动拒绝了它',))“,),)> 追溯(最近一次通话): _new_conn中的第159行“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ connection.py” (self._dns_host,self.port),self.timeout,** extra_kw) 在create_connection中的第80行,文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ util \ connection.py” 提高错误 在create_connection中的第70行,文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ util \ connection.py” sock.connect(sa) ConnectionRefusedError:[WinError 10061]无法建立连接,因为目标计算机主动拒绝了连接
在处理上述异常期间,发生了另一个异常:
回溯(最近通话最近): 文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ connectionpool.py”,行600,在urlopen中 分块=块状) _make_request中的第354行“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ connectionpool.py” conn.request(方法,网址,** httplib_request_kw) 请求中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ http \ client.py”,行1239 self._send_request(方法,URL,正文,标头,encode_chunked) _send_request中的第1285行的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ http \ client.py” self.endheaders(body,encode_chunked = encode_chunked) 文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ http \ client.py”,行1234,在标题中 self._send_output(消息正文,encode_chunked = encode_chunked) _send_output中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ http \ client.py”,行1026 self.send(msg) 发送中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ http \ client.py”,行964 self.connect() 连接中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ connection.py”,行181 conn = self._new_conn() _new_conn中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ connection.py”,行168 自我,“无法建立新连接:%s”%e) urllib3.exceptions.NewConnectionError::无法建立新连接:[WinError 10061]无法建立连接,因为目标计算机主动拒绝了该连接
在处理上述异常期间,发生了另一个异常:
回溯(最近通话最近): 发送中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ requests \ adapters.py”,行449 超时=超时 urlopen中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ connectionpool.py”,第638行 _stacktrace = sys.exc_info()[2]) 文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ urllib3 \ util \ retry.py”,第398行,递增 引发MaxRetryError(_pool,url,error或ResponseError(cause)) urllib3.exceptions.MaxRetryError:HTTPConnectionPool(host ='username.mydomain',port = 80):url超出了最大重试次数:/project/total_visit/count.txt(由NewConnectionError(':导致无法建立新连接:[[ WinError 10061]无法建立连接,因为目标计算机主动拒绝了它,))
在处理上述异常期间,发生了另一个异常:
回溯(最近通话最近): 计划程序中的文件“ C:\ Users \ Administrator \ Desktop \ bot.py”,第33行 等待client.change_presence(game = discord.Game(name ='Total Used:'+ requests.get('http://username.mydomain/project/total_visit/count.txt'。text,type = 3)) 在get中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ requests \ api.py”,第75行 返回请求('get',url,params = params,** kwargs) 请求中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ requests \ api.py” return session.request(method = method,url = url,** kwargs) 请求中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ requests \ sessions.py”,第533行 resp = self.send(准备,** send_kwargs) 发送文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ requests \ sessions.py”,行646 r = adapter.send(request,** kwargs) 发送中的文件“ C:\ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ requests \ adapters.py”,行516 引发ConnectionError(e,request = request) requests.exceptions.ConnectionError:HTTPConnectionPool(host ='username.mydomain',port = 80):url超过了最大重试次数:/project/total_visit/count.txt(由NewConnectionError(':导致:无法建立新连接:[ WinError 10061]无法建立连接,因为目标计算机主动拒绝了它,))
答案 0 :(得分:0)
绝对必须得到错误,您进行了许多get.requests。
要解决它,请尝试(关闭请求)/(重新启动Bot [后台命令])
嗯我还不够好,但是你可以尝试我的脚步
1)添加完整(urllib3库)
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from discord import Game
import math, time
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import urllib3
import urllib3.contrib.pyopenssl
import certifi
2)add(Backgroundworker)命令[将每次重新启动get.request。]
Client = discord.client
client = commands.Bot(command_prefix = '!')
Clientdiscord = discord.Client()
urllib3.contrib.pyopenssl.inject_into_urllib3()
@client.event
async def on_ready():
print('Project Runing..!')
async def task():
await client.wait_until_ready()
while True:
await client.change_presence(game=discord.Game(name='Loading..!', type=3))
print('Get_Url-Refresh')
await asyncio.sleep(1)
print('Total_Used')
one = requests.get('http://username.mydomain/project/total_visit/count.txt', timeout=5)
print('Total_Online')
two = requests.get('http://username.mydomain/project/total_online/Live.php', timeout=5)
print('Total_Users')
three = requests.get('http://username.mydomain/project/total_users/total.php', timeout=5)
await asyncio.sleep(1)
print('Refresh Request')
await asyncio.sleep(10)
print('Running')
await client.change_presence(game=discord.Game(name='steady', type=3))
await asyncio.sleep(5)
await client.change_presence(game=discord.Game(name='ready', type=3))
await asyncio.sleep(5)
await client.change_presence(game=discord.Game(name='go', type=3))
await asyncio.sleep(5)
print('Total Used..!')
await client.change_presence(game=discord.Game(name='Total Used : ' + one.text, type=3))
await asyncio.sleep(5)
print('Online..!')
await client.change_presence(game=discord.Game(name='Online : ' + two.text, type=1))
await asyncio.sleep(5)
print('Total Users..!')
await client.change_presence(game=discord.Game(name='Total Users : ' + three.text, type=3))
await asyncio.sleep(5)
print('Refresh..!')
def handle_exit():
print("Handling")
client.loop.run_until_complete(client.logout())
for t in asyncio.Task.all_tasks(loop=client.loop):
if t.done():
t.exception()
continue
t.cancel()
try:
client.loop.run_until_complete(asyncio.wait_for(t, 5, loop=client.loop))
t.exception()
except asyncio.InvalidStateError:
pass
except asyncio.TimeoutError:
pass
except asyncio.CancelledError:
pass
while True:
@client.event
async def on_message(m):
if m.content == 'die':
print("Terminating")
raise SystemExit
client.loop.create_task(task())
try:
client.loop.run_until_complete(client.start('You_Token_Here'))
except SystemExit:
handle_exit()
except KeyboardInterrupt:
handle_exit()
client.loop.close()
print("Program ended")
break
print("Bot restarting")
client = discord.Client(loop=client.loop)
Dev I.A(玩家控制)的信用。