0

I'm trying to deploy a Flask web app with mysql connectivity. It's my first time using Azure, and coming off Linux it all seems pretty confusing.

My understanding is that one includes within the requirements.txt to include the packages required. When I build the default Flask app from Azure the file looks like this:

Flask<1

At this stage the site loads fine.

If I then include an additional line https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.14.tar.gz As per this answer https://stackoverflow.com/a/34489738/2697874

Then in my views.py file (which seems to be broadly synonymous to my old app.py file) I include...import mysql.connector

I then restart and reload my site...which then returns the error The page cannot be displayed because an internal server error has occurred.

Error logging spits out a load of html (seems pretty weird way to deliver error logs - so I must be missing something here). When I save to html and load it up I get this...

enter image description here

How can I include the mysql.connector library within my Flask web app?

Community
  • 1
  • 1
Ben Mayo
  • 1,285
  • 2
  • 20
  • 37
  • Why do you want to use that specific version, rather than just including `mysql-connector-python` directly in requirements.txt? – Daniel Roseman Nov 22 '16 at 17:24
  • And note that using requirements.txt has nothing to do with Azure vs "Linux". It's good practice on *any* platform. – Daniel Roseman Nov 22 '16 at 17:24
  • I don't have any preference for that specific version. I tried with `mysql-connector-python` too - same result – Ben Mayo Nov 22 '16 at 18:31
  • use this article to enable logging and get back to us with the error. https://blogs.msdn.microsoft.com/azureossds/2015/07/14/troubleshoot-logging-python-application-errors-on-azure-webapi-apps/ – 4c74356b41 Nov 22 '16 at 19:27
  • Awesome - got some decent logging set up. The error is `File ".\FlaskWebProject1\views.py", line 8, in import mysql.connector ImportError: No module named mysql.connector` – Ben Mayo Nov 22 '16 at 20:00

1 Answers1

1

Per my experience, the resoure https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.14.tar.gz is for Linux, not for Azure WebApps based on Windows, and the link seems to be not available now.

I used the command pip search mysql-connector to list the related package. Then, I tried to use mysql-connector instead of mysql-connector-python via pip install, and tried to import mysql.connector in local Python interpreter that works fine.

So please use mysql-connector==2.1.4 instead of mysql-connector-python== in the requirements.txt file of your project using IDE, then re-deploy the project on Azure and try again. The package will be installed automatically as the offical doc said as below.

Package Management
Packages listed in requirements.txt will be installed automatically in the virtual environment using pip. This happens on every deployment, but pip will skip installation if a package is already installed.

Any update, please feel free to let me know.

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