profile
viewpoint

Ask questionscannot import 'run' (aio_compat.py) (only fails in my local environment using VSCode)

I have a very simple azure function that gets a parameter (please see the code at the bottom) and returns a HttpResponse, after running it it fails with:

cannot import name 'run'
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\aio_compat.py", line 84, in <module>
    from asyncio import run, get_running_loop  # NoQA
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\main.py", line 6, in <module>
    from . import aio_compat
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\worker.py", line 5, in <module>
    from azure.functions_worker.main import main

This only happens locally, the deployed function is working appropriately in the azure function service

Investigative information

Please provide the following:

  • Timestamp: 2019-07-08T19:05:00
  • Function App name: HttpTriggerFTPCheck
  • Function name(s) (as appropriate):
  • Core Tools version: win-x64.2.7.1373
  • Python version : Python 3.6.7 :: Anaconda, Inc.

Repro steps

Provide the steps required to reproduce the problem:

I only have a very simple function that gets a parameter and returns a JSON response with that parameter's value..

  1. Debug __init__.py

It's been working for almost one week and suddenly the following error started happening: This only happens in my local environment (PC), not the actual azure function that is deployed already. Not sure about what is going on, I've seen this when there are circular dependencies, but I'm not sure about this case.

<!-- Example:

  1. Step A
  2. Step B

-->

Expected behavior

Provide a description of the expected behavior.

Response with:

"result": "saul"

Actual behavior

Provide a description of the actual behavior observed.

It's been working for almost one week and suddenly the following error started happening:

cannot import name 'run'
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\aio_compat.py", line 84, in <module>
    from asyncio import run, get_running_loop  # NoQA
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\main.py", line 6, in <module>
    from . import aio_compat
  File "c:\users\saul.cruz\appdata\roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\worker.py", line 5, in <module>
    from azure.functions_worker.main import main

Known workarounds

Provide a description of any known workarounds.

<!-- Example:

  • Turn off the circuit breaker for the lights. -->

Related information

Provide any related information

  • Links to source
  • Contents of the requirements.txt file
  • Bindings used
#__init__.py
import logging
import json
import azure.functions as func


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

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(json.dumps({'result': name}))
    else:
        return func.HttpResponse(
             "Please pass a name on the query string or in the request body",
             status_code=400
        )
azure-functions==1.0.0a4
azure-functions-worker==1.0.0a4
grpcio==1.14.2
grpcio-tools==1.14.2
protobuf==3.6.1
six==1.11.0

functions.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

</details>

Azure/azure-functions-python-worker

Answer questions luabud

This doesn't seem to be an issue in the Python extension, this can also be reproduced with other extensions such as CMake Tools and Docker. We're tracking the issue upstream in the VS Code repo here: https://github.com/microsoft/vscode/issues/99699.

FWIW I can still reproduce the same issue when manually installing previous versions of the Python extension, so I'm not sure what is going on.

useful!

Related questions

Python Worker exceeds retry count hot 2
Error importing Shared Code into Python function hot 2
Investigate supporting Conda hot 1
No module named azure.storage hot 1
event hub body cannot be decompressed, when use gzipped event hub as trigger hot 1
I am trying to deploy python function to azure hot 1
libgomp.so serror hot 1
Language Worker Process Exited hot 1
No module named azure.storage hot 1
Import Error when importing modules within same Azure Function hot 1
Importing local module into Python function fails hot 1
502 Bad Gateway on Python Azure Function hot 1
Failed to start language worker for: python. hot 1
Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) hot 1
Errors when running queueTrigger function from the portal hot 1
Github User Rank List