Importing mysql.connector into Azure Flask Project - python

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...
How can I include the mysql.connector library within my Flask web app?

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.

Related

How can I deploy a Flask app containing a Kik bot to Heroku? (Python)

Silly newb question, it seems I can't use git to install content I need in the Heroku console, but my app/bot is dependent on content I normally use that for. I know very little about how git and pip work, or the right terminology to ask a question like this, so bare with me!
I have a bot made with Tomer8007's Kik Bot API that I've embedded in Flask and want to deploy to Heroku. I've deployed Flask sites there before, they work like a charm, but because I import everything to Heroku via git using the Heroku CLI I can't import this one which is already using git.
I normally use these two commands to fetch and install the dependencies I need for that project:
git clone -b new https://github.com/tomer8007/kik-bot-api-unofficial
pip install ./kik-bot-api-unofficial
I tried manually downloading and installing the API without git, but then it throws this error when I tried to run it: "TypeError: Couldn't build proto file into descriptor pool: duplicate file name (google/protobuf/descriptor.proto)", wheras it works perfectly fine when I use the two above commands instead. (This is locally btw).
I also made an attempt to import to heroku before using those commands and instead using them in the heroku console, but it throws a bunch of errors when I try. I also can't import it after using those commands locally, because I already used git. (I'm not sure how that works though, that's why I'm here.)
Everything in procfile.txt, requirements.txt, runtime.txt, etc is fine, the only issue is getting the API for the Kik bot. I've no idea what's going haywire when I attempt to manually download it instead of using git clone, or what alternative options I have. Any pointers?
Apparently, the duplicate file name (google/protobuf/descriptor.proto) error was caused by a breaking change in the protobuf package in versions greater than 4.
This is now fixed, and should also work on Python 3.9+.

Python app hosted on app engine is not able to connect with Firestore where as working on local

I have created a new project on GCP. I am trying to select/add data from firestore (already in native mode) from Python flask app. From local env. I am able to connect to firestore. But once I hosted my app on App engine, my API is not able to connect with Firestore. It's throwing the below error:
TypeError: with_scopes_if_required() got an unexpected keyword argument 'default_scopes'
_create_composite_credentials (/layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/grpc_helpers.py:238)
I am not sure what I am missing here. I appreciate any support.
Thanks
I had the same issue, and I just fixed it today.
As you can see in the changelog https://googleapis.dev/python/google-api-core/latest/changelog.html recently they have updated the requirements for google-auth lib.
You need to check your requirements.txt.
In my case, we had two libs pinned that we weren't using directly.
google-auth==1.21.1
google-auth-oauthlib==0.4.1
I just removed them from the requirements.txt so that dependencies versions are handled automatically, and it solved the issue.
So I guess it depends on your case, on how you are managing dependencies, but you might want to play with google-auth versions.

ModuleNotFoundError: No module named 'icalendar' google Cloud

I'm getting "ModuleNotFoundError: No module named 'icalendar' " after running google app deploy on Gcloud, I have installed the icalendar module using pip but to my surprise i'm getting an error when I try to deploy the app. I have spent hours on this your help will be much appreciated.
According to the official documentation :
Specifying Dependencies
Dependencies for Python applications are declared in a standard
requirements.txt
For example:
Flask==0.10.1
icalendar
Therefore I created a requirements.txt and included icalendar module. Then I deploy to App Engine gcloud app deploy and everything worked as expected.
You can follow this tutorial for better understanding the concept:
Quickstart for Python 3 in the App Engine Standard Environment
Pls. check pip list to see if that has been installed properly. If yes, pls. check that import statement in the python terminal.
If that works, then use which python and ensure that it is the same virtual environment where you are installing and running from.

Deploying python application

I have created a python application containing rest apis which call machine learning code on PyCharm IDE. I want to deploy rest apis on IIS.
I copy and past complete PyCharm project in virtual directory. The issue I am facing is dependencies like tensorflow and keras are not being found due to which API is giving "Internal server error", however I am able to call rest services.
please guide.
As FishingCode suggested please share code snippet to understand the exact issue.
Please include and install requirements.txt file in virtual environment.
Also, you may try installing using docker tutorial

Accessing BigQuery on Google App Engine dev server

I am successfully able to get BQ data from one project to another from the advice in this answer. However this only works when deployed on my development/staging instance and not my local development server on Google App Engine.
My findings are that it works in production because you include:
libraries:
- name: pycrypto
version: "latest"
in app.yaml. However these libraries are not accessible from the dev server. I have tried installing everything locally (Pycrypto, oauth2client, openSSL) after digging through some docs and tracing the error but still cannot get it to work. I have tried installing through pip and manually doing the build/install from the raw files to no avail. Any advice on getting these queries to work on the local django server? Working on Ubuntu if that matters, perhaps it's looking in the wrong spot for the libraries?
If its just the libs that are mising follow this answer https://stackoverflow.com/a/11405769/3877822 to insatll pycrypto to the root of your project
As #Udi suggests in the comment below, the following command also
installs pycrypto and can be used in virtualenv as well:
easy_install
http://www.voidspace.org.uk/downloads/pycrypto26/pycrypto-2.6.win32-py2.7.exe
Notice to choose the relevant link for your setup from this list

Categories

Resources