GraiaProject / Application

一个设计精巧, 协议实现完备的, 基于 mirai-api-http 的即时聊天软件自动化框架.
https://graia-document.vercel.app/
GNU Affero General Public License v3.0
438 stars 63 forks source link

运行bot.py报错:远程主机拒绝连接 #163

Closed LnksW closed 2 years ago

LnksW commented 3 years ago

描述你遇到的问题:

在powershell中运行python bot.py时报错 bot.py内容

from graia.broadcast import Broadcast
from graia.application import GraiaMiraiApplication, Session
from graia.application.message.chain import MessageChain
import asyncio

from graia.application.message.elements.internal import Plain
from graia.application.friend import Friend

loop = asyncio.get_event_loop()

bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(
    broadcast=bcc,
    connect_info=Session(
        host="http://localhost:8080", # 填入 httpapi 服务运行的地址
        authKey="INI******7iG4D", # 填入 authKey
        account=1*******3627, # 你的机器人的 qq 号
        websocket=True # Graia 已经可以根据所配置的消息接收的方式来保证消息接收部分的正常运作.
    )
)

@bcc.receiver("FriendMessage")
async def friend_message_listener(app: GraiaMiraiApplication, friend: Friend):
    await app.sendFriendMessage(friend, MessageChain.create([
        Plain("Hello, World!")
    ]))

app.launch_blocking()

net.mamoe.mirai-api-http的setting.yml

cors: 
  - '*'
host: 0.0.0.0
port: 8080
authKey: INITKEY5kure0XY
cacheSize: 4096
enableWebsocket: true
report: 
  enable: false
  groupMessage: 
    report: true
  friendMessage: 
    report: true
  tempMessage: 
    report: true
  eventMessage: 
    report: true
  destinations: []
  extraHeaders: {}

heartbeat: 
  enable: false
  delay: 1000
  period: 15000
  destinations: []
  extraBody: {}

  extraHeaders: {}

发生错误的代码

PS E:\qqbot> python bot.py
[2021-08-11 17:14:45,832][INFO]: initializing app...
Traceback (most recent call last):
  File "D:\Python\lib\site-packages\aiohttp\connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "D:\Python\lib\asyncio\base_events.py", line 1056, in create_connection
    raise exceptions[0]
  File "D:\Python\lib\asyncio\base_events.py", line 1041, in create_connection
    sock = await self._connect_sock(
  File "D:\Python\lib\asyncio\base_events.py", line 955, in _connect_sock
    await self.sock_connect(sock, address)
  File "D:\Python\lib\asyncio\proactor_events.py", line 702, in sock_connect
    return await self._proactor.connect(sock, address)
  File "D:\Python\lib\asyncio\windows_events.py", line 812, in _poll
    value = callback(transferred, key, ov)
  File "D:\Python\lib\asyncio\windows_events.py", line 599, in finish_connect
    ov.getresult()
ConnectionRefusedError: [WinError 1225] 远程计算机拒绝网络连接。

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\qqbot\bot.py", line 28, in <module>
    app.launch_blocking()
  File "D:\Python\lib\site-packages\graia\application\__init__.py", line 1613, in launch_blocking
    loop.run_until_complete(self.initialize())
  File "D:\Python\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "D:\Python\lib\site-packages\graia\application\__init__.py", line 1503, in initialize
    await self.authenticate()
  File "D:\Python\lib\site-packages\graia\application\utilles.py", line 27, in wrapper
    return await func(self, *args, **kwargs)
  File "D:\Python\lib\site-packages\graia\application\__init__.py", line 301, in authenticate
    async with self.session.post(
  File "D:\Python\lib\site-packages\aiohttp\client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "D:\Python\lib\site-packages\aiohttp\client.py", line 520, in _request
    conn = await self._connector.connect(
  File "D:\Python\lib\site-packages\aiohttp\connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "D:\Python\lib\site-packages\aiohttp\connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "D:\Python\lib\site-packages\aiohttp\connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "D:\Python\lib\site-packages\aiohttp\connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "D:\Python\lib\site-packages\aiohttp\connector.py", line 975, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:8080 ssl:default [远程计算机拒绝网络连 接。]

控制台日志输出截图:

image 红色报错和本项目无关,不明原因,不影响使用 image

运行环境:

SiriusNEO commented 3 years ago

https://github.com/project-mirai/mirai-api-http/issues/435

skommando commented 2 years ago

请问有进展吗,遇到一样的情况。windows 10专业版。 mah-1.12.0 mirai-core-all/mirai-console/mirai-console-terminal - 2.7.0 garia-application-mirai-0.19.2 启动 mcl 无error无warning,bot.py 运行报 aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:8081 ssl:default [远程计算机拒绝网络连接。]

bug 还没修好的话麻烦给个稳定运行的老版本号 谢谢~

skommando commented 2 years ago

新鲜出炉,解决了,应该是 由于不明原因导致 mah 没有跟 mcl 关联上,以下是刚才的操作: 0、config.json 中无 mah 的配置,但是已有 /plugins/mah-1.12.0.jar。 1、运行 ./mcl --update-package net.mamoe:mirai-api-http --channel stable --type plugin & ./mcl,提示由于网络原因无法下载,本地 mah 文件损坏(file xxx corrupted)。 2、手工下载 https://github.com/project-mirai/mirai-api-http/releases/download/v1.12.0/mirai-api-http-v1.12.0.mirai.jar,移到 /plugins。 3、config.json 中移除 mah 配置。 4、运行 ./mcl,再运行 bot.py 无异常。 最终 config.json: image

LnksW commented 2 years ago

@skommando 没解决,直接不用了

BlueGlassBlock commented 2 years ago

@skommando 没解决,直接不用了

See #177

LnksW commented 2 years ago

@skommando 没解决,直接不用了

See #177

主要是没时间折腾了

GreyElaina commented 2 years ago

换用 Ariadne(v4+)

kemomi commented 2 years ago

/permission permittedPermissions