问题描述
我使用 tor 的 http 代理(使用 aiohttp_socks)使用 aiohttp 发送多个请求
完成一些请求后,我收到以下错误:
Traceback (most recent call last):
File "main.py",line 171,in <module>
loop.run_until_complete(future)
File "/usr/lib/python3.8/asyncio/base_events.py",line 616,in run_until_complete
return future.result()
File "main.py",line 95,in get_market_pages
async with session.get(active_link,headers=headers) as response:
File "/home/mrlalatg/.local/lib/python3.8/site-packages/aiohttp/client.py",line 1012,in __aenter__
self._resp = await self._coro
File "/home/mrlalatg/.local/lib/python3.8/site-packages/aiohttp/client.py",line 504,in _request
await resp.start(conn)
File "/home/mrlalatg/.local/lib/python3.8/site-packages/aiohttp/client_reqrep.py",line 847,in start
message,payload = await self._protocol.read() # type: ignore # noqa
File "/home/mrlalatg/.local/lib/python3.8/site-packages/aiohttp/streams.py",line 591,in read
await self._waiter
aiohttp.client_exceptions.ClientOSError: [Errno 1] [SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY] application data after close notify (_ssl.c:2745)
我找不到关于此错误的任何信息,除了关于类似错误的 git 讨论 - github
在那里我找到了一个解决方法 (link),我可以修改它以忽略此错误,但它不起作用,错误仍然存在。
SSL_PROTOCOLS = (asyncio.sslproto.SSLProtocol,)
try:
import uvloop.loop
except ImportError:
pass
else:
SSL_PROTOCOLS = (*SSL_PROTOCOLS,uvloop.loop.SSLProtocol)
def ignore_aiohttp_ssl_eror(loop):
"""Ignore aiohttp #3535 / cpython #13548 issue with SSL data after close
There is an issue in Python 3.7 up to 3.7.3 that over-reports a
ssl.SSLError Fatal error (ssl.SSLError: [SSL: KRB5_S_INIT] application data
after close notify (_ssl.c:2609)) after we are already done with the
connection. See GitHub issues aio-libs/aiohttp#3535 and
python/cpython#13548.
Given a loop,this sets up an exception handler that ignores this specific
exception,but passes everything else on to the prevIoUs exception handler
this one replaces.
Checks for fixed Python versions,disabling itself when running on 3.7.4+
or 3.8.
"""
orig_handler = loop.get_exception_handler()
def ignore_ssl_error(loop,context):
if context.get("message") in {
"SSL error in data received","Fatal error on transport",}:
# validate we have the right exception,transport and protocol
exception = context.get('exception')
protocol = context.get('protocol')
if (
isinstance(exception,ssl.SSLError)
and exception.reason == 'APPLICATION_DATA_AFTER_CLOSE_NOTIFY'
and isinstance(protocol,SSL_PROTOCOLS)
):
if loop.get_debug():
asyncio.log.logger.debug('Ignoring asyncio SSL KRB5_S_INIT error')
return
if orig_handler is not None:
orig_handler(loop,context)
else:
loop.default_exception_handler(context)
loop.set_exception_handler(ignore_ssl_error)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)