Code Monkey home page Code Monkey logo

aiohttp-basicauth-middleware's Introduction

aiohttp-basicauth-middleware

Build Status

Aiohttp middleware for simple http basic auth protection for some urls.

Works with Python โ‰ฅ 3.6.

Works with UTF-8 ๐Ÿ––

Installation

pip install aiohttp-basicauth-middleware

Usage

app = web.Application(loop=loop)

app.router.add_route('GET', '/hello', handler_a)
app.router.add_route('GET', '/admin/hello', handler_b)

app.middlewares.append(
   basic_auth_middleware(
      ('/admin',),
      {'user': 'password'},
   )
)

basic_auth_middleware has 3 params:

  1. list of protected urls. For example ['/admin'] will match with /admin/user, but will not match with /user/admin.
  2. auth dict โ€“ a dict with pairs: login-password.
  3. strategy (optional) for password comparision. For example you can store hashed password in auth_dict. See aiohttp_basicauth_middleware.strategy.BaseStrategy and example.strategy for more information.

Example with md5 password hashing:

app = web.Application(loop=loop)

app.router.add_route('GET', '/hello', handler_a)
app.router.add_route('GET', '/admin/hello', handler_b)

app.middlewares.append(
    basic_auth_middleware(
        ('/admin',),
        {'user': '5f4dcc3b5aa765d61d8327deb882cf99'},
        lambda x: hashlib.md5(bytes(x, encoding='utf-8')).hexdigest(),
    )
)

/admin/... will be accessed by the same login+password pair ('user', 'password').

aiohttp-basicauth-middleware's People

Contributors

bugov avatar namuyan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bob81135

aiohttp-basicauth-middleware's Issues

Add strategy classes

Example:

import asyncio
from aiohttp import web
from aiohttp_basicauth_middleware import basic_auth_middleware
from aiohttp_basicauth_middleware.strategy import BaseStrategy


class SkipOptionsStrategy(BaseStrategy):
    async def check(self):
        if self.request.method == 'OPTIONS':
            return await self.handler(self.request)

        return super().check(self.login, self.password)


def hello(request):
    return web.Response(text='Hello')


def get_app(loop, auth_dict=None):
    if auth_dict is None:
        auth_dict = {}

    app = web.Application(loop=loop)
    app.router.add_route('*', '/admin/hello', hello)

    app.middlewares.append(
        basic_auth_middleware(('/admin',), auth_dict, SkipOptionsStrategy)
    )

    return app


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    web.run_app(get_app(loop))

How to protect the POST and not the GET of a REST api?

    class ProtectStrategy(BaseStrategy):
        async def check(self):
            # Only protect POST
            if self.request.method in ['GET']:            
                return await self.handler(self.request)
            return await super().check()

    app.middlewares.append(
        basic_auth_middleware(('/admin',), auth_dict, ProtectStrategy)
    )

Can't install using PIP on Windows

As Administrator in Command Prompt

C:\WINDOWS\system32>python --version
Python 3.9.11

C:\WINDOWS\system32>python -m pip install aiohttp-basicauth-middleware
Collecting aiohttp-basicauth-middleware
  Using cached aiohttp-basicauth-middleware-1.2.0.tar.gz (4.7 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  ร— python setup.py egg_info did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> [52 lines of output]
      WARNING: The wheel package is not available.
      WARNING: The wheel package is not available.
      WARNING: The wheel package is not available.
        error: subprocess-exited-with-error

        python setup.py bdist_wheel did not run successfully.
        exit code: 1

        [7 lines of output]
        WARNING: The wheel package is not available.
        usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
           or: setup.py --help [cmd1 cmd2 ...]
           or: setup.py --help-commands
           or: setup.py cmd --help

        error: invalid command 'bdist_wheel'
        [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for http_basic_auth
      ERROR: Failed to build one or more wheels
      Traceback (most recent call last):
        File "C:\Program Files\Python39\lib\site-packages\setuptools\installer.py", line 75, in fetch_build_egg
          subprocess.check_call(cmd)
        File "C:\Program Files\Python39\lib\subprocess.py", line 373, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['C:\\Program Files\\Python39\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\admin\\AppData\\Local\\Temp\\tmpbrpwggfr', '--quiet', 'http_basic_auth']' returned non-zero exit status 1.

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

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\admin\AppData\Local\Temp\pip-install-eapkhq3t\aiohttp-basicauth-middleware_3433c061f43840ba80d42ee23b672f04\setup.py", line 12, in <module>
          setup(
        File "C:\Program Files\Python39\lib\site-packages\setuptools\__init__.py", line 152, in setup
          _install_setup_requires(attrs)
        File "C:\Program Files\Python39\lib\site-packages\setuptools\__init__.py", line 147, in _install_setup_requires
          dist.fetch_build_eggs(dist.setup_requires)
        File "C:\Program Files\Python39\lib\site-packages\setuptools\dist.py", line 806, in fetch_build_eggs
          resolved_dists = pkg_resources.working_set.resolve(
        File "C:\Program Files\Python39\lib\site-packages\pkg_resources\__init__.py", line 766, in resolve
          dist = best[req.key] = env.best_match(
        File "C:\Program Files\Python39\lib\site-packages\pkg_resources\__init__.py", line 1051, in best_match
          return self.obtain(req, installer)
        File "C:\Program Files\Python39\lib\site-packages\pkg_resources\__init__.py", line 1063, in obtain
          return installer(requirement)
        File "C:\Program Files\Python39\lib\site-packages\setuptools\dist.py", line 877, in fetch_build_egg
          return fetch_build_egg(self, req)
        File "C:\Program Files\Python39\lib\site-packages\setuptools\installer.py", line 77, in fetch_build_egg
          raise DistutilsError(str(e)) from e
      distutils.errors.DistutilsError: Command '['C:\\Program Files\\Python39\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\admin\\AppData\\Local\\Temp\\tmpbrpwggfr', '--quiet', 'http_basic_auth']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

ร— Encountered error while generating package metadata.
โ•ฐโ”€> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

C:\WINDOWS\system32>

Basically the same issue when I tried with Python 3.10.

Issue installing on arm/v7

Hi,

I'm trying to install aiohttp-basicauth-middleware in a docker container built for an arm/v7 host, but I get the error below. I tried building from the master instead of latest tag which is quite old, but I got the same error.

Do you know what the issue is? Thanks

#9 151.1 Collecting aiohttp>=3.01
#9 151.2   Downloading aiohttp-3.8.1.tar.gz (7.3 MB)
#9 154.7   Installing build dependencies: started
#9 171.4   Installing build dependencies: finished with status 'done'
#9 171.4   Getting requirements to build wheel: started
#9 175.4   Getting requirements to build wheel: finished with status 'done'
#9 175.4   Installing backend dependencies: started
#9 182.5   Installing backend dependencies: finished with status 'done'
#9 182.5   Preparing metadata (pyproject.toml): started
#9 186.5   Preparing metadata (pyproject.toml): finished with status 'done'
#9 186.7 Collecting aiohttp-basicauth-middleware==1.1.2
#9 186.7   Downloading aiohttp-basicauth-middleware-1.1.2.tar.gz (3.9 kB)
#9 186.8   Preparing metadata (setup.py): started
#9 218.9   Preparing metadata (setup.py): finished with status 'error'
#9 218.9   ERROR: Command errored out with exit status 1:
#9 218.9    command: /usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-_7hppwit/aiohttp-basicauth-middleware_55a5eb8fffe04cb9996f73c4f8a3a5f4/setup.py'"'"'; __file__='"'"'/tmp/pip-install-_7hppwit/aiohttp-basicauth-middleware_55a5eb8fffe04cb9996f73c4f8a3a5f4/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-31f6ktut
#9 218.9        cwd: /tmp/pip-install-_7hppwit/aiohttp-basicauth-middleware_55a5eb8fffe04cb9996f73c4f8a3a5f4/
#9 218.9   Complete output (152 lines):
#9 218.9   /usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
#9 218.9     warnings.warn(msg)
#9 218.9   warning: no files found matching 'aiohttp' anywhere in distribution
#9 218.9   warning: no previously-included files matching '*.pyc' found anywhere in distribution
#9 218.9   warning: no previously-included files matching '*.pyd' found anywhere in distribution
#9 218.9   warning: no previously-included files matching '*.so' found anywhere in distribution
#9 218.9   warning: no previously-included files matching '*.lib' found anywhere in distribution
#9 218.9   warning: no previously-included files matching '*.dll' found anywhere in distribution
#9 218.9   warning: no previously-included files matching '*.a' found anywhere in distribution
#9 218.9   warning: no previously-included files matching '*.obj' found anywhere in distribution
#9 218.9   warning: no previously-included files found matching 'aiohttp/*.html'
#9 218.9   no previously-included directories found matching 'docs/_build'
#9 218.9   Traceback (most recent call last):
#9 218.9     File "/usr/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile
#9 218.9       extra_postargs)
#9 218.9     File "/usr/lib/python3.6/distutils/ccompiler.py", line 909, in spawn
#9 218.9       spawn(cmd, dry_run=self.dry_run)
#9 218.9     File "/usr/lib/python3.6/distutils/spawn.py", line 36, in spawn
#9 218.9       _spawn_posix(cmd, search_path, dry_run=dry_run)
#9 218.9     File "/usr/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix
#9 218.9       % (cmd, exit_status))
#9 218.9   distutils.errors.DistutilsExecError: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
#9 218.9
#9 218.9   During handling of the above exception, another exception occurred:
#9 218.9
#9 218.9   Traceback (most recent call last):
#9 218.9     File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
#9 218.9       dist.run_commands()
#9 218.9     File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
#9 218.9       self.run_command(cmd)
#9 218.9     File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
#9 218.9       cmd_obj.run()
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/bdist_egg.py", line 172, in run
#9 218.9       cmd = self.call_command('install_lib', warn_dir=0)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/bdist_egg.py", line 158, in call_command
#9 218.9       self.run_command(cmdname)
#9 218.9     File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
#9 218.9       self.distribution.run_command(command)
#9 218.9     File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
#9 218.9       cmd_obj.run()
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/install_lib.py", line 24, in run
#9 218.9       self.build()
#9 218.9     File "/usr/lib/python3.6/distutils/command/install_lib.py", line 109, in build
#9 218.9       self.run_command('build_ext')
#9 218.9     File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
#9 218.9       self.distribution.run_command(command)
#9 218.9     File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
#9 218.9       cmd_obj.run()
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 78, in run
#9 218.9       _build_ext.run(self)
#9 218.9     File "/usr/lib/python3.6/distutils/command/build_ext.py", line 339, in run
#9 218.9       self.build_extensions()
#9 218.9     File "/usr/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
#9 218.9       self._build_extensions_serial()
#9 218.9     File "/usr/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
#9 218.9       self.build_extension(ext)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 199, in build_extension
#9 218.9       _build_ext.build_extension(self, ext)
#9 218.9     File "/usr/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
#9 218.9       depends=ext.depends)
#9 218.9     File "/usr/lib/python3.6/distutils/ccompiler.py", line 574, in compile
#9 218.9       self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
#9 218.9     File "/usr/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile
#9 218.9       raise CompileError(msg)
#9 218.9   distutils.errors.CompileError: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
#9 218.9
#9 218.9   During handling of the above exception, another exception occurred:
#9 218.9
#9 218.9   Traceback (most recent call last):
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 154, in save_modules
#9 218.9       yield saved
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 195, in setup_context
#9 218.9       yield
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 250, in run_setup
#9 218.9       _execfile(setup_script, ns)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 45, in _execfile
#9 218.9       exec(code, globals, locals)
#9 218.9     File "/tmp/easy_install-27ckh15p/aiohttp-4.0.0a1/setup.py", line 124, in <module>
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 129, in setup
#9 218.9       return distutils.core.setup(**attrs)
#9 218.9     File "/usr/lib/python3.6/distutils/core.py", line 163, in setup
#9 218.9       raise SystemExit("error: " + str(msg))
#9 218.9   SystemExit: error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
#9 218.9
#9 218.9   During handling of the above exception, another exception occurred:
#9 218.9
#9 218.9   Traceback (most recent call last):
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1163, in run_setup
#9 218.9       run_setup(setup_script, args)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 253, in run_setup
#9 218.9       raise
#9 218.9     File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
#9 218.9       self.gen.throw(type, value, traceback)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 195, in setup_context
#9 218.9       yield
#9 218.9     File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
#9 218.9       self.gen.throw(type, value, traceback)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 166, in save_modules
#9 218.9       saved_exc.resume()
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 141, in resume
#9 218.9       six.reraise(type, exc, self._tb)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/_vendor/six.py", line 685, in reraise
#9 218.9       raise value.with_traceback(tb)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 154, in save_modules
#9 218.9       yield saved
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 195, in setup_context
#9 218.9       yield
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 250, in run_setup
#9 218.9       _execfile(setup_script, ns)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 45, in _execfile
#9 218.9       exec(code, globals, locals)
#9 218.9     File "/tmp/easy_install-27ckh15p/aiohttp-4.0.0a1/setup.py", line 124, in <module>
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 129, in setup
#9 218.9       return distutils.core.setup(**attrs)
#9 218.9     File "/usr/lib/python3.6/distutils/core.py", line 163, in setup
#9 218.9       raise SystemExit("error: " + str(msg))
#9 218.9   SystemExit: error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
#9 218.9
#9 218.9   During handling of the above exception, another exception occurred:
#9 218.9
#9 218.9   Traceback (most recent call last):
#9 218.9     File "<string>", line 1, in <module>
#9 218.9     File "/tmp/pip-install-_7hppwit/aiohttp-basicauth-middleware_55a5eb8fffe04cb9996f73c4f8a3a5f4/setup.py", line 45, in <module>
#9 218.9       long_description=read('README.rst')
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 128, in setup
#9 218.9       _install_setup_requires(attrs)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 123, in _install_setup_requires
#9 218.9       dist.fetch_build_eggs(dist.setup_requires)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 513, in fetch_build_eggs
#9 218.9       replace_conflicting=True,
#9 218.9     File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 774, in resolve
#9 218.9       replace_conflicting=replace_conflicting
#9 218.9     File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1057, in best_match
#9 218.9       return self.obtain(req, installer)
#9 218.9     File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1069, in obtain
#9 218.9       return installer(requirement)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 580, in fetch_build_egg
#9 218.9       return cmd.easy_install(req)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 698, in easy_install
#9 218.9       return self.install_item(spec, dist.location, tmpdir, deps)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 724, in install_item
#9 218.9       dists = self.install_eggs(spec, download, tmpdir)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 909, in install_eggs
#9 218.9       return self.build_and_install(setup_script, setup_base)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1177, in build_and_install
#9 218.9       self.run_setup(setup_script, setup_base, args)
#9 218.9     File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1165, in run_setup
#9 218.9       raise DistutilsError("Setup script exited with %s" % (v.args[0],))
#9 218.9   distutils.errors.DistutilsError: Setup script exited with error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
#9 218.9   **********************
#9 218.9   * Accellerated build *
#9 218.9   **********************
#9 218.9   ----------------------------------------
#9 218.9 WARNING: Discarding https://files.pythonhosted.org/packages/89/b8/28c31077da33db6c077b3ab45b57c40a550748029c0a66d9dd00eb3d130d/aiohttp-basicauth-middleware-1.1.2.tar.gz#sha256=fb4ff3b5733ab4475dc21ecb30636542ed74c12e9eb711ac77b61795f25eb104 (from https://pypi.org/simple/aiohttp-basicauth-middleware/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#9 218.9 ERROR: Could not find a version that satisfies the requirement aiohttp-basicauth-middleware==1.1.2 (from versions: 0.1.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.1.1, 1.1.2, 1.1.3)
#9 218.9 ERROR: No matching distribution found for aiohttp-basicauth-middleware==1.1.2

example doesn't work.

TypeError: basic_auth_middleware() missing 1 required positional argument: 'strategy'

from aiohttp import web
from aiohttp_basicauth_middleware import basic_auth_middleware
async def public_view(request):
    return web.Response(text='Public view')
async def secret_view(request):
    return web.Response(text='Secret view')
app = web.Application()
app.router.add_route('GET', '/public', public_view)
app.router.add_route('GET', '/secret', secret_view)
app.middlewares.append(
    basic_auth_middleware(
        ('/public',),
        {'user': 'password'},
    )
)
web.run_app(app, host='127.0.0.1', port=80)

pip can't install v.1.1.1 and v.1.1.2

Hi! Thank you for this useful package. However there is a problem. I can install v.1.1.0, but can't 1.1.1 or v.1.1.2 (the latest on pypi is 1.1.2). I think the best I can do is to attach the full log:

(env) ^^/C/h/modulbank_auth >>> pip install aiohttp-basicauth-middleware                                                                                                     (1) ^(*test+1807) 18:48:05
Collecting aiohttp-basicauth-middleware
  Using cached aiohttp-basicauth-middleware-1.1.2.tar.gz (3.9 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/mac/Code/hice/modulbank_auth/env/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_26a2645a0afa4084aa70a88cc6531e30/setup.py'"'"'; __file__='"'"'/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_26a2645a0afa4084aa70a88cc6531e30/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-pip-egg-info-7ftu3r60
         cwd: /private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_26a2645a0afa4084aa70a88cc6531e30/
    Complete output (46 lines):
    WARNING: The wheel package is not available.
    WARNING: The wheel package is not available.
      ERROR: Command errored out with exit status 1:
       command: /Users/mac/Code/hice/modulbank_auth/env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-wheel-qapuo0s4/http-basic-auth_caf2d39623db4043989414f86711d0b2/setup.py'"'"'; __file__='"'"'/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-wheel-qapuo0s4/http-basic-auth_caf2d39623db4043989414f86711d0b2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-wheel-j43qxcr4
           cwd: /private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-wheel-qapuo0s4/http-basic-auth_caf2d39623db4043989414f86711d0b2/
      Complete output (7 lines):
      WARNING: The wheel package is not available.
      usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
         or: setup.py --help [cmd1 cmd2 ...]
         or: setup.py --help-commands
         or: setup.py cmd --help

      error: invalid command 'bdist_wheel'
      ----------------------------------------
      ERROR: Failed building wheel for http-basic-auth
    ERROR: Failed to build one or more wheels
    Traceback (most recent call last):
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/setuptools/installer.py", line 75, in fetch_build_egg
        subprocess.check_call(cmd)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['/Users/mac/Code/hice/modulbank_auth/env/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/tmpthf1ka9q', '--quiet', 'http_basic_auth']' returned non-zero exit status 1.

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

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_26a2645a0afa4084aa70a88cc6531e30/setup.py", line 12, in <module>
        setup(
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/setuptools/__init__.py", line 152, in setup
        _install_setup_requires(attrs)
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/setuptools/__init__.py", line 147, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/setuptools/dist.py", line 686, in fetch_build_eggs
        resolved_dists = pkg_resources.working_set.resolve(
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/pkg_resources/__init__.py", line 766, in resolve
        dist = best[req.key] = env.best_match(
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/pkg_resources/__init__.py", line 1051, in best_match
        return self.obtain(req, installer)
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/pkg_resources/__init__.py", line 1063, in obtain
        return installer(requirement)
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/setuptools/dist.py", line 745, in fetch_build_egg
        return fetch_build_egg(self, req)
      File "/Users/mac/Code/hice/modulbank_auth/env/lib/python3.9/site-packages/setuptools/installer.py", line 77, in fetch_build_egg
        raise DistutilsError(str(e)) from e
    distutils.errors.DistutilsError: Command '['/Users/mac/Code/hice/modulbank_auth/env/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/tmpthf1ka9q', '--quiet', 'http_basic_auth']' returned non-zero exit status 1.
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/89/b8/28c31077da33db6c077b3ab45b57c40a550748029c0a66d9dd00eb3d130d/aiohttp-basicauth-middleware-1.1.2.tar.gz#sha256=fb4ff3b5733ab4475dc21ecb30636542ed74c12e9eb711ac77b61795f25eb104 (from https://pypi.org/simple/aiohttp-basicauth-middleware/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading aiohttp-basicauth-middleware-1.1.1.tar.gz (4.0 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/mac/Code/hice/modulbank_auth/env/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_3ad12c6dce444d14bb08a973b2ab5a8a/setup.py'"'"'; __file__='"'"'/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_3ad12c6dce444d14bb08a973b2ab5a8a/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-pip-egg-info-rgjzi56r
         cwd: /private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_3ad12c6dce444d14bb08a973b2ab5a8a/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_3ad12c6dce444d14bb08a973b2ab5a8a/setup.py", line 4, in <module>
        from aiohttp_basicauth_middleware import __version__
      File "/private/var/folders/nf/762fth4x5pz1hvgj5hfl93hr0000gn/T/pip-install-wum7ddkm/aiohttp-basicauth-middleware_3ad12c6dce444d14bb08a973b2ab5a8a/aiohttp_basicauth_middleware/__init__.py", line 27, in <module>
        from http_basic_auth import parse_header, BasicAuthException
    ModuleNotFoundError: No module named 'http_basic_auth'
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/69/82/ce1a48d8016bfe80a7b289955dbf8f4931add1995c4c6db4366d4f1242f4/aiohttp-basicauth-middleware-1.1.1.tar.gz#sha256=336370fcae8dc75fdab07a988f0afbedcace50968cd4a3eefa778883980a1e59 (from https://pypi.org/simple/aiohttp-basicauth-middleware/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading aiohttp_basicauth_middleware-1.1.0-py3-none-any.whl (4.8 kB)
Collecting http-basic-auth
  Using cached http-basic-auth-1.2.0.tar.gz (3.5 kB)
Requirement already satisfied: aiohttp in ./env/lib/python3.9/site-packages (from aiohttp-basicauth-middleware) (3.7.3)
Requirement already satisfied: attrs>=17.3.0 in ./env/lib/python3.9/site-packages (from aiohttp->aiohttp-basicauth-middleware) (20.3.0)
Requirement already satisfied: chardet<4.0,>=2.0 in ./env/lib/python3.9/site-packages (from aiohttp->aiohttp-basicauth-middleware) (3.0.4)
Requirement already satisfied: multidict<7.0,>=4.5 in ./env/lib/python3.9/site-packages (from aiohttp->aiohttp-basicauth-middleware) (5.1.0)
Requirement already satisfied: yarl<2.0,>=1.0 in ./env/lib/python3.9/site-packages (from aiohttp->aiohttp-basicauth-middleware) (1.6.3)
Requirement already satisfied: typing-extensions>=3.6.5 in ./env/lib/python3.9/site-packages (from aiohttp->aiohttp-basicauth-middleware) (3.7.4.3)
Requirement already satisfied: async-timeout<4.0,>=3.0 in ./env/lib/python3.9/site-packages (from aiohttp->aiohttp-basicauth-middleware) (3.0.1)
Requirement already satisfied: idna>=2.0 in ./env/lib/python3.9/site-packages (from yarl<2.0,>=1.0->aiohttp->aiohttp-basicauth-middleware) (2.10)
Using legacy 'setup.py install' for http-basic-auth, since package 'wheel' is not installed.
Installing collected packages: http-basic-auth, aiohttp-basicauth-middleware
    Running setup.py install for http-basic-auth ... done
Successfully installed aiohttp-basicauth-middleware-1.1.0 http-basic-auth-1.2.0

Fails to install from PyPI

Here's a Dockerfile illustrating the problem:

FROM ubuntu:18.04

RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install python3-pip

RUN pip3 install aiohttp-basicauth-middleware

Fails with:

Step 4/4 : RUN pip3 install aiohttp-basicauth-middleware
 ---> Running in 72e2ee0c4716
Collecting aiohttp-basicauth-middleware
  Downloading https://files.pythonhosted.org/packages/69/82/ce1a48d8016bfe80a7b289955dbf8f4931add1995c4c6db4366d4f1242f4/aiohttp-basicauth-middleware-1.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-zzwt_tq8/aiohttp-basicauth-middleware/setup.py", line 4, in <module>
        from aiohttp_basicauth_middleware import __version__
      File "/tmp/pip-build-zzwt_tq8/aiohttp-basicauth-middleware/aiohttp_basicauth_middleware/__init__.py", line 26, in <module>
        from aiohttp import web
    ModuleNotFoundError: No module named 'aiohttp'

It seems like setup.py egg_info tries to import dependencies, but they haven't been installed yet when it's invoked by pip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.