Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error ConnectError: All connection attempts failed occurred when I tried to generate images by using re_edge_gpt.ImageGenAsync #57

Closed
WindowsSov8forUs opened this issue Nov 23, 2023 · 7 comments
Labels
invalid This doesn't seem right

Comments

@WindowsSov8forUs
Copy link

An error occurred when I tried to generate images by using re_edge_gpt.ImageGenAsync .

The same error occurred when I tried to use re_edge_gpt.Chatbot to.

There is my code using re_edge_gpt.ImageGenAsync :

# Bing Chat 类
class BingChat():
    '''Bing Chat 类'''
    id_chats: dict[str, 'BingChat'] = {}
    '''ID-Chatbot 存储字典'''
    uid_chats: dict[str, 'BingChat'] = {}
    '''UID-Chatbot 存储字典'''
    cookies: Cookies = Cookies.get()
    '''使用的 `Cookies` 对象'''
    image_gen: ImageGenAsync
    '''异步图片生成器'''
    # 生成图片
    @classmethod
    async def gen_image(cls, prompt: str) -> Union[list[str], str]:
        '''生成图片

        参数:
            prompt (str): 图片生成参数

        返回:
            Union[list[str], str]: 生成的图片列表或错误信息
        '''
        try:
            cls.image_gen = ImageGenAsync(
                auth_cookie=cls.cookies.image_gen,
                quiet=True,
                all_cookies=cls.cookies.chat,
                proxy=PROXY
            )
            image_list = await cls.image_gen.get_images(prompt)
            if image_list is not None:
                return image_list
            else:
                return '没有图片生成。'
        except Exception as exception:
            raise exception
            return f'{type(exception).__name__}: {exception}'

def image_gen(prompt: str) -> ImageGenResponse:
    '''图片生成器响应

    参数:
        prompt (str): 图片生成参数

    返回:
        ImageGenResponse: 图片生成结果
    '''
    # 构建响应字典
    response : ImageGenResponse= {
        'status': False,
        'response': ''
    }
    # 获取参数
    result = asyncio.run(BingChat.gen_image(prompt))
    if isinstance(result, str):
        response['response'] = result
    else:
        response['status'] = True
        response['response'] = result
    
    return response

and there is the error traceback:

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\anyio\_core\_sockets.py", line 168, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\anyio\_backends\_asyncio.py", line 2202, in connect_tcp
    await get_running_loop().create_connection(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1085, in create_connection
    raise exceptions[0]
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1069, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 973, in _connect_sock
    await self.sock_connect(sock, address)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\selector_events.py", line 634, in sock_connect
    return await fut
           ^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\selector_events.py", line 674, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 10061] Connect call failed ('127.0.0.1', 7089)

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

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_exceptions.py", line 10, in map_exceptions
    yield
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_backends\anyio.py", line 114, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\anyio\_core\_sockets.py", line 230, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

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

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
    yield
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_async\connection_pool.py", line 262, in handle_async_request
    raise exc
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_async\connection_pool.py", line 245, in handle_async_request
    response = await connection.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_async\http_proxy.py", line 271, in handle_async_request
    connect_response = await self._connection.handle_async_request(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_async\connection.py", line 92, in handle_async_request
    raise exc
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_async\connection.py", line 69, in handle_async_request
    stream = await self._connect(request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_async\connection.py", line 117, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_backends\auto.py", line 31, in connect_tcp
    return await self._backend.connect_tcp(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_backends\anyio.py", line 112, in connect_tcp
    with map_exceptions(exc_map):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "D:\WindowsSov8\Anon_Chihaya_bot_satori/plugin\plugin_gpt\__init__.py", line 130, in bing_image_gen
    response = image_gen(prompt)
               ^^^^^^^^^^^^^^^^^
  File "D:\WindowsSov8\Anon_Chihaya_bot_satori/plugin\plugin_gpt\bing_chat_gpt.py", line 376, in image_gen
    result = asyncio.run(BingChat.gen_image(prompt))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "D:\WindowsSov8\Anon_Chihaya_bot_satori/plugin\plugin_gpt\bing_chat_gpt.py", line 234, in gen_image
    raise exception
  File "D:\WindowsSov8\Anon_Chihaya_bot_satori/plugin\plugin_gpt\bing_chat_gpt.py", line 228, in gen_image
    image_list = await cls.image_gen.get_images(prompt)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\re_edge_gpt\image_genearation.py", line 316, in get_images
    response = await self.session.post(
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py", line 1848, in post
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py", line 1530, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py", line 1617, in send
    response = await self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py", line 1645, in _send_handling_auth
    response = await self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py", line 1682, in _send_handling_redirects
    response = await self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py", line 1719, in _send_single_request
    response = await transport.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed
@JE-Chen
Copy link
Member

JE-Chen commented Nov 23, 2023

Look more like net problem not package problem.

@JE-Chen
Copy link
Member

JE-Chen commented Nov 23, 2023

Maybe proxy block by Microsoft? I don't know.

@JE-Chen JE-Chen added the invalid This doesn't seem right label Nov 23, 2023
@JE-Chen
Copy link
Member

JE-Chen commented Nov 24, 2023

Can't reproduce this exception on my Windows 11 & Ubuntu 22.04

@JE-Chen
Copy link
Member

JE-Chen commented Nov 24, 2023

看看这个 issue 的网路问题部分 (我用 Bing 翻译的)
lss233/chatgpt-mirai-qq-bot#1034

@WindowsSov8forUs
Copy link
Author

Can't reproduce this exception on my Windows 11 & Ubuntu 22.04

This problem may be caused by the proxy issue of my server, I will check it first

@WindowsSov8forUs
Copy link
Author

I have checked it out, it is indeed caused by the proxy issue of my server, sorry for the trouble, I will close this issue

@JE-Chen
Copy link
Member

JE-Chen commented Nov 24, 2023

Never mind, have a nice day !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants