【发布时间】:2019-05-30 17:44:57
【问题描述】:
您好,在我的代码中它破坏了我的请求,我尝试了几次,但 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")
从未检索到任务异常 未来:异常=ConnectionError(MaxRetryError(“HTTPConnectionPool(主机='username.mydomain',端口=80):最大重试次数超过了url:/project/total_visit/count.txt(由NewConnectionError引起(':无法建立新的连接:[WinError 10061] 无法建立连接,因为目标机器主动拒绝它',))",),)> 回溯(最近一次通话最后): _new_conn 中的文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connection.py”,第 159 行 (self._dns_host, self.port), self.timeout, **extra_kw) 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\connection.py”,第 80 行,在 create_connection 提出错误 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\connection.py”,第 70 行,在 create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] 由于目标机器主动拒绝,无法建立连接
在处理上述异常的过程中,又发生了一个异常:
Traceback(最近一次调用最后一次): 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py”,第 600 行,在 urlopen 分块=分块) _make_request 中的文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py”,第 354 行 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 中的文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第 1285 行 self.endheaders(正文,encode_chunked=encode_chunked) 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第 1234 行,在 endheaders self._send_output(message_body, encode_chunked=encode_chunked) _send_output 中的文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第 1026 行 自我发送(味精) 文件“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 行 self, "建立新连接失败: %s" % e) urllib3.exceptions.NewConnectionError: : 无法建立新连接:[WinError 10061] 由于目标机器主动拒绝,无法建立连接
在处理上述异常的过程中,又发生了一个异常:
Traceback(最近一次调用最后一次): 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py”,第 449 行,发送 超时=超时 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py”,第 638 行,在 urlopen _stacktrace=sys.exc_info()[2]) 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\retry.py”,第 398 行,增量 raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='username.mydomain', port=80): Max retries exceeded with url: /project/total_visit/count.txt (由 NewConnectionError(': 无法建立新连接: [ WinError 10061] 由于目标机器主动拒绝,无法建立连接',))
在处理上述异常的过程中,又发生了一个异常:
Traceback(最近一次调用最后一次): 调度程序中的文件“C:\Users\Administrator\Desktop\bot.py”,第 33 行 await client.change_presence(game=discord.Game(name='Total Used : '+requests.get('http://username.mydomain/project/total_visit/count.txt').text, type=3)) 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py”,第 75 行,在 get 返回请求('get', url, params=params, **kwargs) 文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py”,第 60 行,在请求中 返回 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(prep, **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): Max retries exceeded with url: /project/total_visit/count.txt (由 NewConnectionError(': 无法建立新连接: [ WinError 10061] 由于目标机器主动拒绝,无法建立连接',))
【问题讨论】:
标签: python-3.x python-requests python-multithreading discord.py