0

I have deployed the base version of the Flask Appbuilder application on azure under the URL: Site URL. The admin login has been created using the Kudu console with ID as admin and password as admin The login keeps on redirecting to itself with an "Invalid login. Please try again." error, however the user exists in the app.db file itself. The redirect does not create any logs on Azure.

Error portion and log

We have an important deployment coming up, any leads to resolve this would be appreciated.

Thanks

Environment

Flask-Appbuilder version: latest

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
Zedi10
  • 115
  • 2
  • 10
  • Python apps should be hosted on Azure App Service on Linux now, https://blog.lextudio.com/shifting-to-azure-app-service-on-linux-b216f4584b03 – Lex Li Feb 16 '19 at 16:58
  • I will try to migrate to linux, in the meantime would anyone have any lead to get it working. – Zedi10 Feb 17 '19 at 13:45
  • Would anyone have any idea on how to go about resolving this – Zedi10 Feb 18 '19 at 17:08

1 Answers1

0

It sounds like your Python application built by flask-appbuilder was deployed on Azure WebApp for Windows, but not works.

There are my answers for two existing SO threads Hosting Flask(Python) app throws CGI error and Hosting Flask(python) API on Azure API.

I tried to create a demo via flask-appbuilder in Python 3 and deploy it to Azure WebApp for Windows, then it works fine. Here is my steps below which you can refer to.

  1. I create a virtual environment for this demo via the commands below on my local machine that I have installed Python 3 runtime and virtualenv via pip install virtualenv.

    virtualenv demo
    cd demo
    bin\activate.bat
    pip install flask-appbuilder
    fabmanager create-app # use `demoapp` as the `Your new app name` input
    cd demoapp
    
  2. To create admin with all default options and a simple password via fabmanager create-admin.

    Username [admin]:
    User first name [admin]:
    User last name [user]:
    Email [admin@fab.org]:
    Password:
    Repeat for confirmation:
    D:\<your path>\demo\demoapp\lib\python3.6\site-packages\flask_sqlalchemy\__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
      'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
    2019-02-21 15:29:55,309:INFO:flask_appbuilder.security.sqla.manager:Security DB not found Creating all Models from Base
    2019-02-21 15:29:55,334:INFO:flask_appbuilder.security.sqla.manager:Security DB Created
    .......
    
  3. I run the demoapp via fabmanager run and it works on my local.
  4. Then, I drag all my directories and files of demoapp that include app.db into my Azure WebApp via Kudo Console https://<your webapp name>.scm.azurewebsites.net/DebugConsole.
  5. Due to not directly install the app dependencies for flash-appbuilder, I installed a Python 3 runtime in the Site extensions of Kudu, as the figure below.

    enter image description here

  6. Continues, I back to Kudu Console and run the commands below to install flask-appbuilder.

    D:\home>cd python364x64 D:\home\python364x64>python -V Python 3.6.4 D:\home\python364x64>pip install flask-appbuilder Collecting flask-appbuilder Downloading https://files.pythonhosted.org/packages/3a/b0/edb3e54241203266222c4863ae6eb30fd49f5d331a117b61f1801e8124da/Flask-AppBuilder-1.12.3.tar.gz (2.3MB) Requirement already satisfied: colorama<1,>=0.3.9 in d:\home\python364x86\lib\site-packages (from flask-appbuilder) (0.4.1) Requirement already satisfied: click<8,>=6.7 in d:\home\python364x86\lib\site-packages (from flask-appbuilder) (7.0) ......

  7. Then, to move into site\wwwroot to create & configure a web.config file and change the code in run.py. There are two ways to make it works, as below.

    • Not using WSGI. The default port of Azure WebApp is depended on the environment variable HTTP_PLATFORM_PORT which be set by IIS on Azure. So we need to change the port parameter of app.run method in run.py and configure web.config as below.

    The run.py code changed as below:

    from app import app
    import os
    
    app.run(port=int(os.environ['HTTP_PLATFORM_PORT']))
    

    And the web.config content as below:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <appSettings>
            <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
            <add key="PATH" value="D:\home\python364x64;D:\home\python364x64\Scripts;%PATH%" />
        </appSettings>
        <system.webServer>
            <handlers>
                <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
            </handlers>
            <httpPlatform processPath="D:\home\python364x64\python.exe" arguments="D:\home\site\wwwroot\run.py --port %HTTP_PLATFORM_PORT%" stdoutLogEnabled="true" startupRetryCount='10'>
            </httpPlatform>
          </system.webServer>
    </configuration>
    
    • Using WSGI server instead for production environment.

    The run.py code as below.

    from app import app
    
    app.run()
    

    And the web.config content as below.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
         <appSettings>
              <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
              <add key="WSGI_HANDLER" value="app.app" />
         </appSettings>
         <system.webServer>
              <handlers>
                  <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x64\python.exe|D:\home\python364x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
              </handlers>
         </system.webServer>
    </configuration>
    

It works via access https://<your app name>.azurewebsites.net enter image description here

Peter Pan
  • 23,476
  • 4
  • 25
  • 43