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

[aiohttp.web] TypeError: Application.__call__() takes 1 positional argument but 2 were given #7017

Closed
1 task done
4n1qz5skwv opened this issue Oct 13, 2022 · 7 comments
Closed
1 task done
Labels

Comments

@4n1qz5skwv
Copy link

4n1qz5skwv commented Oct 13, 2022

Describe the bug

Trying use "aiohttp" with "nginx unit"

aiohttp is not listed in https://unit.nginx.org/howto/#frameworks

So, tried to use basic ASGI approach. Not working.

To Reproduce

  1. a simple run.py
from aiohttp import web

app = web.Application()
  1. configure unit file. a sample of application section,
  "applications": {
    "fooapp": {
      "type": "python 3.10",
      "home": "/path/to/.venv/",
      "path": "/path/to/run.py/folder/",
      "protocol": "asgi",
      "module": "run",
      "callable": "app"
    }
  }
  1. put it online.
  2. visit url.

Expected behavior

Expected behavior:

404: Not Found

Actual behavior:

Error 503.

Logs/tracebacks

/var/log/unit.log (https://unit.nginx.org/installation/#ubuntu)

2022/10/13 12:30:14 [error] 573242#573242 [unit] #3193: Python failed to call legacy app stage1
TypeError: Application.__call__() takes 1 positional argument but 2 were given

Python Version

$ python --version
3.10

aiohttp Version

$ python -m pip show aiohttp
aiohttp==3.8.3

multidict Version

$ python -m pip show multidict

yarl Version

$ python -m pip show yarl

OS

ubuntu 22.04

Related component

Server

Additional context

Please add support for unit.

https://unit.nginx.org/
https://unit.nginx.org/howto/#frameworks

If possible please add this library to unit frameworks list with a demo. It will be very very helpful for us to get started.

Thank you for this awesome lib.

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@4n1qz5skwv 4n1qz5skwv added the bug label Oct 13, 2022
@4n1qz5skwv
Copy link
Author

If this library added to unit frameworks it will be at top of the list (alphabetical order) 😃

@Dreamsorcerer
Copy link
Member

I'm not too familiar with exactly how WSGI works, but our docs suggest either deploying with a proxy over unix socket (https://docs.aiohttp.org/en/stable/deployment.html#nginx-supervisord) or with Gunicorn (https://docs.aiohttp.org/en/stable/deployment.html#nginx-gunicorn).

I think the gunicorn worker creates a WSGI interface (atleast I see references to wsgi in the code: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/worker.py), so maybe you just need to make use of Gunicorn in order to give Unit a WSGI environment to work with?

If you figure it out, we can consider taking any changes or updating the docs if it's not obvious.

To be clear though, the web.Application object does not handle running the program, so your example will definitely not work, you need some kind of runner, e.g. a regular application run would use: https://docs.aiohttp.org/en/stable/web_reference.html#aiohttp.web.run_app or https://docs.aiohttp.org/en/stable/web_advanced.html#application-runners).

@4n1qz5skwv
Copy link
Author

WSGI

ASGI ?

@4n1qz5skwv
Copy link
Author

4n1qz5skwv commented Oct 13, 2022

WSGI

I tried with protocol "asgi" (https://unit.nginx.org/configuration/#python) .

so your example will definitely not work

I know. But all the popular lib already supported and listed there. I don't know how the unit works actually. It just works with all the similar libraries. So i thought may be it support aiohttp too.

If you can please consider adding support for unit 🙏

@Dreamsorcerer

@Dreamsorcerer
Copy link
Member

WSGI

ASGI ?

Seem to be similar, Unit says it supports both, and I suspect you can get Gunicorn to do either too.

I know. But all the popular lib already supported and listed there. I don't know how the unit works actually. It just works with all the similar libraries. So i thought may be it support aiohttp too.

Docs say it just uses WSGI or ASGI (https://unit.nginx.org/#supported-app-languages), so I doubt we need Unit-specific config. But, other libraries often use these as the default method of running their applications, whereas we default to running on a socket. So, you'll just need play around to figure it out. Again, Gunicorn may provide what you need, so I'd start looking there.

@bmwant
Copy link
Member

bmwant commented Nov 7, 2022

@4n1qz5skwv aiohttp doesn't support ASGI, so you would not be able to run it as described unless you provide your own wrapper around.

See #2902

@Dreamsorcerer
Copy link
Member

I'm going to close this as a duplicate of #8473, as it doesn't look like there's any other approach that Unit will work other than ASGI.

@Dreamsorcerer Dreamsorcerer closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants