yokonsan / midjourney-api

midjourney in discord api.
777 stars 176 forks source link

🐛 请问国内部署的话使用方法呢?docker 机器上装个代理吗? #48

Open GoldThree opened 1 year ago

GoldThree commented 1 year ago

问题简述

如果是国内服务器部署的话,会访问 discord.com不通,而又因为项目使用了 discord.py 的 lib,所以大批量替换 host 也不太可能,但是服务器安装代理有点重了,有什么比较好的方法吗?

复现方式

暂无

环境信息

额外信息

如描述

一点点的自我检查

yokonsan commented 1 year ago

这个我目前是部署在海外机器的 后续我看下怎么处理吧

qiulang commented 10 months ago

可以这样解决,在 listener.py 里 commands.Bot 加上 proxy 参数

intents = Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="", intents=intents, proxy="http://127.0.0.1:xxxx") # 设置你自己的代理
qiulang commented 10 months ago

server.py 需要设置proxy地方可以这么改, 在 ./lib/api/discord.py

async def trigger(payload: Dict[str, Any]):
    async with aiohttp.ClientSession(
            timeout=aiohttp.ClientTimeout(total=30),
            headers=HEADERS
    ) as session:
   # 这里加上 proxy参数
    return await fetch(session, TRIGGER_URL, proxy="http://127.0.0.1:xxxx", data=json.dumps(payload)) 
liflash22 commented 10 months ago

感谢[qiulang]给出的 proxy 的设置,目前可以通过本机代理 连接了

ljjy1 commented 9 months ago

我写了一个springboot的中间件 支持代理 支持多账号切换 可以看一下https://github.com/ljjy1/discord-mj-java

yayaQAQ commented 9 months ago
Traceback (most recent call last):
  File "/Users/apple/Downloads/midjourney-api/task_bot.py", line 13, in <module>
    bot.run(BOT_TOKEN)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/discord/client.py", line 860, in run
    asyncio.run(runner())
  File "/usr/local/anaconda3/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/anaconda3/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/local/anaconda3/lib/python3.9/site-packages/discord/client.py", line 849, in runner
    await self.start(token, reconnect=reconnect)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/discord/client.py", line 777, in start
    await self.login(token)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/discord/client.py", line 612, in login
    data = await self.http.static_login(token)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/discord/http.py", line 801, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/usr/local/anaconda3/lib/python3.9/site-packages/discord/http.py", line 624, in request
    async with self.__session.request(method, url, **kwargs) as response:
  File "/usr/local/anaconda3/lib/python3.9/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
  File "/usr/local/anaconda3/lib/python3.9/site-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
  File "/usr/local/anaconda3/lib/python3.9/site-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/aiohttp/connector.py", line 899, in _create_connection
    _, proto = await self._create_proxy_connection(req, traces, timeout)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/aiohttp/connector.py", line 1328, in _create_proxy_connection
    return await self._start_tls_connection(
  File "/usr/local/anaconda3/lib/python3.9/site-packages/aiohttp/connector.py", line 1126, in _start_tls_connection
    raise client_error(req.connection_key, OSError(msg))
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discord.com:443 ssl:default [None]

可以这样解决,在 listener.py 里 commands.Bot 加上 proxy 参数

intents = Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="", intents=intents, proxy="http://127.0.0.1:xxxx") # 设置你自己的代理

我按照上面的流程修改了,会报这个ssl的错误,是aiohttp的版本不对吗?

yayaQAQ commented 9 months ago
image
yayaQAQ commented 9 months ago

我使用的版本是python 3.11,其余的包都是按照requirements.txt来安装的。

liflash22 commented 8 months ago

我的也开始报 443 的错了 , 之前填proxy代理能正常的 什么都没改

liflash22 commented 8 months ago

我使用的版本是python 3.11,其余的包都是按照requirements.txt来安装的。

应该是版本问题, 新版解决了 用代理恢复正常!!