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

Update http.py add proxy support for get_from_cdn #9964

Closed
wants to merge 1 commit into from

Conversation

CloudyAvalon
Copy link
Contributor

add proxy support for get_from_cdn

Summary

Update http.py add proxy support for get_from_cdn

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

add proxy support for get_from_cdn
@CloudyAvalon
Copy link
Contributor Author

I'm using discord.py behind proxy, and it failed to get message attachment from discord with following stack:

[2024-10-11 16:39:14] [ERROR ] discord: Failed to handle msg: Traceback (most recent call last):
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1073, in _wrap_create_connection
sock = await aiohappyeyeballs.start_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohappyeyeballs\impl.py", line 104, in start_connection
raise first_exception
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohappyeyeballs\impl.py", line 81, in start_connection
sock = await _connect_sock(
^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohappyeyeballs\impl.py", line 166, in _connect_sock
await loop.sock_connect(sock, address)
File "E:\Program Files\Python311\Lib\asyncio\proactor_events.py", line 726, in sock_connect
return await self._proactor.connect(sock, address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Program Files\Python311\Lib\asyncio\windows_events.py", line 846, in _poll
value = callback(transferred, key, ov)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Program Files\Python311\Lib\asyncio\windows_events.py", line 633, in finish_connect
ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

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

Traceback (most recent call last):
File "E:\Code\cloudyavalon\discord_scan/main.py", line 79, in send_discord_msg
f_data = await attachment.read(use_cached=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\discord\message.py", line 336, in read
data = await self._http.get_from_cdn(url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\discord\http.py", line 783, in get_from_cdn
async with self.__session.get(url) as resp:
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\client.py", line 1353, in aenter
self._resp = await self._coro
^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\client.py", line 657, in _request
conn = await self._connector.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 564, in connect
proto = await self._create_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 975, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1350, in _create_direct_connection
raise last_exc
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1319, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1088, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host cdn.discordapp.com:443 ssl:default [信号灯超时时间已到]

[2024-10-11 16:39:35] [ERROR ] discord: Failed to handle msg: Traceback (most recent call last):
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1073, in _wrap_create_connection
sock = await aiohappyeyeballs.start_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohappyeyeballs\impl.py", line 104, in start_connection
raise first_exception
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohappyeyeballs\impl.py", line 81, in start_connection
sock = await _connect_sock(
^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohappyeyeballs\impl.py", line 166, in _connect_sock
await loop.sock_connect(sock, address)
File "E:\Program Files\Python311\Lib\asyncio\proactor_events.py", line 726, in sock_connect
return await self._proactor.connect(sock, address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Program Files\Python311\Lib\asyncio\windows_events.py", line 846, in _poll
value = callback(transferred, key, ov)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Program Files\Python311\Lib\asyncio\windows_events.py", line 633, in finish_connect
ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

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

Traceback (most recent call last):
File "E:\Code\cloudyavalon\discord_scan/main.py", line 79, in send_discord_msg
f_data = await attachment.read(use_cached=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\discord\message.py", line 336, in read
data = await self._http.get_from_cdn(url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\discord\http.py", line 783, in get_from_cdn
async with self.__session.get(url) as resp:
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\client.py", line 1353, in aenter
self._resp = await self._coro
^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\client.py", line 657, in _request
conn = await self._connector.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 564, in connect
proto = await self._create_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 975, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1350, in _create_direct_connection
raise last_exc
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1319, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\Code\cloudyavalon\discord_scan.venv\Lib\site-packages\aiohttp\connector.py", line 1088, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host cdn.discordapp.com:443 ssl:default [信号灯超时时间已到]

@Rapptz
Copy link
Owner

Rapptz commented Oct 11, 2024

Hello, it seems this PR is formatted incorrectly.

This is okay! This repository uses CI (Continuous Integration) to ensure that all library files are formatted properly. It uses a program called black to accomplish this. You can download it by doing pip install -U black==22.6.

The settings for black are located in the root directory of the project where the pyproject.toml is located. Make sure to run black discord/ examples/ in the directory where the pyproject.toml is located and it should all fix the formatting issues.

Thanks!

@CloudyAvalon
Copy link
Contributor Author

I

Hello, it seems this PR is formatted incorrectly.

This is okay! This repository uses CI (Continuous Integration) to ensure that all library files are formatted properly. It uses a program called black to accomplish this. You can download it by doing pip install -U black==22.6.

The settings for black are located in the root directory of the project where the pyproject.toml is located. Make sure to run black discord/ examples/ in the directory where the pyproject.toml is located and it should all fix the formatting issues.

Thanks!

Thanks, I'll correct it.

@CloudyAvalon CloudyAvalon deleted the zxy54-patch-get_from_cdn branch October 11, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants