aio-libs / aiohttp

Asynchronous HTTP client/server framework for asyncio and Python
https://docs.aiohttp.org
Other
14.78k stars 1.97k forks source link

Http post request is trying to turn into an https request #6806

Open skier233 opened 2 years ago

skier233 commented 2 years ago

Describe the bug

I am making an http request and against my will, aiohttp is trying to execute it is an https request but is failing because it doesn't have a certificate:

        logger.warning(f"Debug: url {url} ssl:{sslcontext} params:{self.combine_parameters(kwargs)} kwargs:{kwargs} headers:{headers}")
        async with session.request(
            method,
            url,
            headers=headers,
            params=self.combine_parameters(kwargs),
            ssl=sslcontext,
            **kwargs,

To Reproduce

        logger.warning(f"Debug: url {url} ssl:{sslcontext} params:{self.combine_parameters(kwargs)} kwargs:{kwargs} headers:{headers}")
        async with session.request(
            method,
            url,
            headers=headers,
            params=self.combine_parameters(kwargs),
            ssl=sslcontext,
            **kwargs,

Expected behavior

aiohttp should execute the call as an http request instead of an https request

Logs/tracebacks

Debug: url http://localhost:5278/webhook ssl:None

Traceback (most recent call last):
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\rasa\core\actions\action.py", line 741, in run
    response: Any = await self.action_endpoint.request(
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\rasa\utils\endpoints.py", line 167, in request
    async with session.request(
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\aiohttp\client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\aiohttp\client.py", line 520, in _request
    conn = await self._connector.connect(
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\aiohttp\connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\aiohttp\connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\aiohttp\connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\aiohttp\connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "c:\coding\testing\aichatbot\venv\lib\site-packages\aiohttp\connector.py", line 971, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host localhost:7278 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')]

Python Version

3.8.0

aiohttp Version

3.7.4

multidict Version

5.2.0

yarl Version

1.7.2

OS

Windows in python virtual environment

Related component

Client

Additional context

No response

Code of Conduct

Dreamsorcerer commented 2 years ago

I'm pretty sure that's not what aiohttp does. Try using allow_redirect=False: https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession.trace_config

If it stops requesting a secure connection, then you know it's your app trying to redirect to https.

Dreamsorcerer commented 2 years ago

I notice that the URL is /webhook, won't you need a websocket for that anyway? https://docs.aiohttp.org/en/stable/client_quickstart.html#websockets

skier233 commented 2 years ago

Not in this case

Dreamsorcerer commented 2 years ago

Another thing worth doing is updating aiohttp. There are several known issues in the 3.7 release, so better try with 3.8.