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

Exception while running simple aiohttp server #851

Closed
ashish01 opened this issue Aug 13, 2014 · 1 comment
Closed

Exception while running simple aiohttp server #851

ashish01 opened this issue Aug 13, 2014 · 1 comment

Comments

@ashish01
Copy link

I am running the following command

gunicorn ex:HttpRequestHandler -b 0.0.0.0:8080 -k gaiohttp

and I am getting following exception

Error: class uri 'gaiohttp' invalid or not found: 

[Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/util.py", line 139, in load_class
    mod = import_module('.'.join(components))
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2201, in _find_and_load_unlocked
ImportError: No module named 'gunicorn.workers.gaiohttp'
]

The contents of ex.py are

"""Basic http server with minimal setup"""
import aiohttp
import aiohttp.server

import asyncio
from urllib.parse import urlparse, parse_qsl
from aiohttp.multidict import MultiDict


class HttpRequestHandler(aiohttp.server.ServerHttpProtocol):

    @asyncio.coroutine
    def handle_request(self, message, payload):
        response = aiohttp.Response(
            self.writer, 200, http_version=message.version)
        get_params = MultiDict(parse_qsl(urlparse(message.path).query))
        if message.method == 'POST':
            post_params = yield from payload.read()
        else:
            post_params = None
        content = "<h1>It Works!</h1>"
        if get_params:
            content += "<h2>Get params</h2><p>" + str(get_params) + "</p>"
        if post_params:
            content += "<h2>Post params</h2><p>" + str(post_params) + "</p>"
        bcontent = content.encode('utf-8')
        response.add_header('Content-Type', 'text/html; charset=UTF-8')
        response.add_header('Content-Length', str(len(bcontent)))
        response.send_headers()
        response.write(bcontent)
        yield from response.write_eof()
@berkerpeksag
Copy link
Collaborator

Thanks for the report. This is a duplicate of #830.

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

No branches or pull requests

2 participants