Skip to content

Can't import WsgiMiddleware #52

@cecilphillip

Description

@cecilphillip

I just created a new functions project and tried to import WsgiMiddleware as mentioned in #45, but it won't resolve for some reason.

I'm using Python 3.7.4, core tools version 3.0.2245, and v1.2.0 of the azure-functions package

from azure.functions import (
    HttpRequest,
    HttpRequest,
    WsgiMiddleware,
    Context
)

def web_application(env, start_response, ):
    status = '200 OK'
    headers = [('Content-type', 'text/html')]
    start_response(status, headers)

    return[b'<strong>Raw WSGI application!!<strong>']


def main(req: HttpRequest,  context: Context) -> HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    return WsgiMiddleware(web_application).main(req, context)

Running the code above results in

[3/19/2020 8:10:25 AM]  INFO: Starting Azure Functions Python Worker.
[3/19/2020 8:10:25 AM]  INFO: Worker ID: 06c1081b-5d78-4298-9895-3171d3d6cb21, Request ID: e3580ac0-97a4-4504-b69c-674bdc108fc0, Host Address: 127.0.0.1:58404
[3/19/2020 8:10:25 AM]  INFO: Successfully opened gRPC channel to 127.0.0.1:58404
[3/19/2020 8:10:25 AM]  INFO: Received WorkerInitRequest, request ID e3580ac0-97a4-4504-b69c-674bdc108fc0
[3/19/2020 8:10:25 AM]  INFO: Received FunctionLoadRequest, request ID: e3580ac0-97a4-4504-b69c-674bdc108fc0, function ID: 09177bec-68a3-464d-8fef-59a47aa70125
[3/19/2020 8:10:25 AM]  INFO: Successfully processed FunctionLoadRequest, request ID: e3580ac0-97a4-4504-b69c-674bdc108fc0, function ID: 09177bec-68a3-464d-8fef-59a47aa70125
[3/19/2020 8:10:25 AM]  INFO: Received FunctionLoadRequest, request ID: e3580ac0-97a4-4504-b69c-674bdc108fc0, function ID: fa8828e4-d216-4ebc-9794-cbbcd9b70fed
[3/19/2020 8:10:25 AM] Worker failed to function id fa8828e4-d216-4ebc-9794-cbbcd9b70fed.
[3/19/2020 8:10:25 AM] Result: Failure
[3/19/2020 8:10:25 AM] Exception: ImportError: cannot import name 'WsgiMiddleware' from 'azure.functions' (/usr/local/Cellar/azure-functions-core-tools@3/3.0.2245/workers/python/3.7/OSX/X64/azure/functions/__init__.py)
[3/19/2020 8:10:25 AM] Stack:   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2245/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
[3/19/2020 8:10:25 AM]     func_request.metadata.entry_point)
[3/19/2020 8:10:25 AM]   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2245/workers/python/3.7/OSX/X64/azure_functions_worker/loader.py", line 66, in load_function
[3/19/2020 8:10:25 AM]     mod = importlib.import_module(fullmodname)
[3/19/2020 8:10:25 AM]   File "/Users/cecilphillip/.pyenv/versions/3.7.4/lib/python3.7/importlib/__init__.py", line 127, in import_module
[3/19/2020 8:10:25 AM]     return _bootstrap._gcd_import(name[level:], package, level)
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
[3/19/2020 8:10:25 AM]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[3/19/2020 8:10:25 AM]   File "/Users/cecilphillip/Desktop/toss/WsgiApi/__init__.py", line 1, in <module>
[3/19/2020 8:10:25 AM]     from azure.functions import (
[3/19/2020 8:10:25 AM] .
[3/19/2020 8:10:25 AM] Host restarted.
[3/19/2020 8:10:25 AM] Stopping 

@Hazhzeng am I missing something?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions