Python Web App using "asyncio" not starting, has "invalid syntax" error

Mike Bond 11 Reputation points
2021-01-13T18:04:25.117+00:00

I have a Flask application that uses "asyncio" and using Python Web App deployment. It runs locally within docker with no issues.
After deploying the applications, it refuses to start with an "invalid syntax" error within the standard "asyncio" library.

This happens with either of the Python 3.7 or 3.8 containers.

Error output (example):

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,807 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Cliverson Obrzut 21 Reputation points
    2021-08-17T21:17:50.19+00:00

    I´m also getting the same issue using Python 3.9. Any simple solution?

    ![124027-image.png]1

    2 people found this answer helpful.
    0 comments No comments

  2. Malte Winckler 6 Reputation points
    2022-08-09T07:24:14.287+00:00

    Hi, initially, I also had the same error with the deployed container. For me simply excluding the asyncio from the pip-requirements did the trick. When you are using Python >= 3.4, asyncio comes with Python as a provisional package.

    Cheers, Malte

    1 person found this answer helpful.
    0 comments No comments

  3. Grmacjon-MSFT 18,216 Reputation points
    2021-01-15T15:43:29.257+00:00

    Hi @Mike Bond ,

    You could try re-installing Python 3.8 to fix this issue or follow the solutions provided in this similar SO post

    "From version 3.7 async and await are reserved keywords. Copy and open the path (without init.py). You will get a list of .py files
    Rename async.py to _async.py or anything you want, as async is now a reserved keyword with us from version 3.7. Once renamed, modify the new name everywhere."

    if the issue persists please let us know so we can investigate further.

    Thanks,
    Grace


  4. Mike Bond 11 Reputation points
    2021-01-15T16:57:36.823+00:00

    TRIED TO SUBMIT A COMMENT - The "Submit" button doesn't work in Edge, Chrome, Firefox, or Safari

    Please note the following:

    1) This is coming from the BASE Python library for asyncio and has the same error in Python 3.7 and 3.8. What you aren't seeing from the screenshot is that further up in the stacktrace, it is triggered by an "import asyncio" line (base Python, not a PyPi install).
    2) Re-installing Python is not an option as this is running in a docker appsvc container provided by Microsoft Azure App Service Python deployments.
    3) This works fine in my local docker container using a slightly older container: "appsvc/python:3.8_20200522.6"
    4) This works fine running in Python 3.8 under WSL2 also.
    5) I realize that "async" and "await" are reserved Python keywords, this is not the issue.

    Yes, I saw that article when originally looking into this issue, that is not what is happening here.
    Question: Does Microsoft have some specific kernel options enabled/disabled?

    I completely rewrote my the "asyncio" library for my application to remove the Python "asyncio" library dependency and it works fine.

    0 comments No comments

  5. Ashish Kesarkar 61 Reputation points
    2021-05-15T18:17:48.993+00:00

    Im getting exact same error. Im also running it on Azure WebApp
    Is there any easiest solution to this other than rewriting library?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.