Unable to successfully run 'func host start

2019-08-20 20:06发布

问题:

I'm trying to perform some local testing of a python azure function following the MSDN instructions here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python

I've installed all the necessary dependencies including Python 3.6, Azure Functions Core Tools, Azure CLI & I have an active Azure subscription. I've also signed into my Azure accont via az login in powershell administrator mode.

Once I've gone through the prompted steps in the MSDN doc & run func host start powershell outputs the following snippet. The error that sticks out to me is AttributeError: module 'azure.functions_worker' has no attribute 'start_async'. I've researched this error & have seen others successfully resolve it by uninstalling & reinstalling azure-functions-core-tools via chocolatey which I've done by following the thread here: Azure Python App Function no longer runs locally - module 'azure.functions_worker' has no attribute 'start_async'

Problem still persists & i'm unable to locally host the azure function & test GET/POST requests in the browser (http://localhost:7071/api/HttpTrigger) Please help me out if you're familiar with how to fix this problem. I thought this could be an issue with my Python version but I confirmed Python 3.6.0 is installed by running python --version in powershell

Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.

Http Functions:

        HttpTrigger: [GET,POST] http://localhost:7071/api/HttpTrigger

[6/26/2019 1:24:31 AM] Traceback (most recent call last):
[6/26/2019 1:24:31 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 37, in main
[6/26/2019 1:24:31 AM]     return aio_compat.run(azure.functions_worker.start_async(
[6/26/2019 1:24:31 AM] AttributeError: module 'azure.functions_worker' has no attribute 'start_async'
[6/26/2019 1:24:31 AM] Traceback (most recent call last):
[6/26/2019 1:24:31 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 46, in <module>
[6/26/2019 1:24:31 AM]     main()
[6/26/2019 1:24:31 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 37, in main
[6/26/2019 1:24:31 AM]     return aio_compat.run(azure.functions_worker.start_async(
[6/26/2019 1:24:31 AM] AttributeError: module 'azure.functions_worker' has no attribute 'start_async'
[6/26/2019 1:24:31 AM] Language Worker Process exited.
[6/26/2019 1:24:31 AM] python exited with code 1
 AttributeError: module 'azure.functions_worker' has no attribute 'start_async'.
[6/26/2019 1:24:31 AM] Starting language worker process:python  "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py" --host 127.0.0.1 --port 64242 --workerId afead7f3-0f5e-4209-91f5-7904d3319d56 --requestId 9a2be9af-32d1-4199-9aaa-0d4aef01eef2 --grpcMaxMessageLength 134217728
[6/26/2019 1:24:31 AM] python process with Id=2360 started
[6/26/2019 1:24:31 AM] Traceback (most recent call last):
[6/26/2019 1:24:31 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 37, in main
[6/26/2019 1:24:31 AM]     return aio_compat.run(azure.functions_worker.start_async(
[6/26/2019 1:24:31 AM] AttributeError: module 'azure.functions_worker' has no attribute 'start_async'
[6/26/2019 1:24:31 AM] Traceback (most recent call last):
[6/26/2019 1:24:31 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 46, in <module>
[6/26/2019 1:24:31 AM]     main()
[6/26/2019 1:24:31 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 37, in main
[6/26/2019 1:24:31 AM]     return aio_compat.run(azure.functions_worker.start_async(
[6/26/2019 1:24:31 AM] AttributeError: module 'azure.functions_worker' has no attribute 'start_async'
[6/26/2019 1:24:31 AM] Language Worker Process exited.
[6/26/2019 1:24:31 AM] python exited with code 1
 AttributeError: module 'azure.functions_worker' has no attribute 'start_async'.
[6/26/2019 1:24:31 AM] Starting language worker process:python  "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py" --host 127.0.0.1 --port 64242 --workerId 899213f3-400d-4355-a0cb-a42e425ef551 --requestId 2e8c49ea-6b15-444a-9e97-a07eefe09808 --grpcMaxMessageLength 134217728
[6/26/2019 1:24:31 AM] python process with Id=10060 started
[6/26/2019 1:24:32 AM] Traceback (most recent call last):
[6/26/2019 1:24:32 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 37, in main
[6/26/2019 1:24:32 AM]     return aio_compat.run(azure.functions_worker.start_async(
[6/26/2019 1:24:32 AM] AttributeError: module 'azure.functions_worker' has no attribute 'start_async'
[6/26/2019 1:24:32 AM] Traceback (most recent call last):
[6/26/2019 1:24:32 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 46, in <module>
[6/26/2019 1:24:32 AM]     main()
[6/26/2019 1:24:32 AM]   File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools\tools\workers\python\worker.py", line 37, in main
[6/26/2019 1:24:32 AM]     return aio_compat.run(azure.functions_worker.start_async(
[6/26/2019 1:24:32 AM] AttributeError: module 'azure.functions_worker' has no attribute 'start_async'
[6/26/2019 1:24:32 AM] Language Worker Process exited.
[6/26/2019 1:24:32 AM] python exited with code 1
 AttributeError: module 'azure.functions_worker' has no attribute 'start_async'.
[6/26/2019 1:24:32 AM] Exceeded language worker restart retry count for runtime:python. Shutting down Functions Host
[6/26/2019 1:24:32 AM] Shuttingdown Rpc Channels Manager
[6/26/2019 1:24:32 AM] Stopping host...
[6/26/2019 1:24:32 AM] Stopping JobHost
[6/26/2019 1:24:32 AM] Job host stopped
[6/26/2019 1:24:32 AM] Host shutdown completed.
Application is shutting down...

回答1:

I uninstalled Python 3.6.0 then installed python 3.6.8 in a virtual environment. Then uninstalled & re-installed azure-functions-core-tools in the same virtual environment which resolved the problem. Uninstallations & installations done via chocolatey in CMD. I also temporarily disabled Windows Defender real-time scans.