Error in deployment of a flask web app with MongoDB Atlas - python

i am new in developing web apps so i might get confused a lot of times!
The problem is this:
I was developing with Pycharm son sort of basic social network, and at first when you sign up the users were created in local folder as JSON files and then i look foward to make a deployment, and i did it without problem using PythonAnywere (PA). Lets call my .py file "server.py" where i have the whole thing.
Then i started looking for some cloud service and I ended modifying everything in order to work with Mongodb Atlas and it was a complete success. I made a lot of local test using Pycharm and everything is OK, the users are now created on cloud service.
My problem is that i would like to make a deployment test with that Mongodb service version, and i was trying to use (PA) again but this time its give me a lot of errors.
Note: i already install all the requirements in (PA) from pip freeze requirements.txt
Is there a problem with PA and MongoDB? is ther any other better option?
Should it run ok if the first version of "server.py" was ok?
I just replaced that file with new one, that was runnning perfect on localhost.
If you need more info just tell me, i am very new in this.
Thanks a lot

Related

App works locally but crashes on Heroku because of Databases connection

Stack communities,
I need your help. I’ve just written my first app in Python with the dash libraries. I am now trying to deploy thanks to the Heroku frameworks. It first works but when trying to connect it my database (PostGre), it crashed. I think it’s because my connection btw Heroku/PostGre SQL is not working correctly.
I’ve tried many changes within my code but still don’t understand why my app crash.
When I try to run the app, I get the following error within the heroku log :
Image of the Heroku error within the server log
My code can be found here in my Github repositorie.
As of now, my database consists of a giant CSV master file because I want to keep it simple for now.
Link to the Database (Private): https://s3-eu-west-1.amazonaws.com/iag-test1/Test1.csv
*On Heroku it seems that I should use the AWS-S3 and connect it. But I didn't manage to do it.
The goal of this project is to build an end-to-end visualization tool in python and deploy it. (I decided to use Dash Library and Heroku to deploy it). Maybe I should switch to AWS...
Any help/advice would be greatly appreciated…

Need advice on how to incorporate Python into an Azure, specifically an ASP.NET web application environment

Need advice on how to incorporate Python into an Azure ASP.NET web application environment. Please excuse this question but I am new to Azure and I'm not clear on how to proceed. Every option that I look into looks promising but they all seem to have their own issues. Below is a more thorough explanation but the deal is that I have an Azure account with all kinds of goodies, a full fledged ASP.NET (C#) web app running via App Service, I am new to Azure (but not Python), and I'm hoping to add Python functionality to this whole setup. In short:
I want to add Python to this setup mainly to run scheduled jobs and also to trigger Python code from ASP.NET web form submissions
ideally I want a solution that resembles a non-cloud setup. I know this sounds silly but I'm finding the cloud/Azure functionality to be nuanced and not straightforward. I want a place to put a bunch of Python scripts, run, edit, schedule and trigger them from ASP.NET
for example: I created a WebJob that runs manually and from the documentation it wasn't clear how it should be called. I just figured out that you need to POST with Basic Auth (and the credentials provided).
!Also, Azure CMD does NOT like files with 'underscore _' in them! You cannot submit a Web Job with a py file with an underscore nor can you write output with a file with an underscore
!Also, I don't see an option for this Web Job to run Python 3.6.4 (which I installed via extension). Right now it is using 2.7.15...
!Also, CRON expression in Azure has six *, not five plus a command. Again, more weird stuff to worry about
I tried these instructions but the updates to the web page's Web.config file breaks the ASP.NET web pages
ideally the most cost effective option
Any info is greatly appreciated
MORE DETAILED EXPLANATION
Currently I have an ASP.NET site running via Azure App Service and I would like to add Python scripts and possibly Flask/Rest functionality. Note that I am not expecting to serve any content via Python and will largely be running Python scripts either on a scheduled basis or call them from ASP.NET. As a matter of fact, and this is an important point, I'm hoping to have ASP.NET trigger/run a Python script when a web form is submitted. I realize that I could get a similar effect if I make a web call to a Rest api that is running Python. In any event, I can't tell if I should:
add a Python extension to the current App Service running the web page (I tried this) OR
I did install Python 3.6.4 and some packages via pip
These instructions were useful, however the updates to the web page's Web.config file breaks the ASP.NET web pages
set up a VM that will have all of the Python code (but how can I have the .NET web page(s) call the Python in the VM?) OR
use Azure functions (I'm completely new to this and must admit that I prefer to have my old school Python environment instead although I see the benefit of using functions. But how do you deal with logging and debugging?)
or what about a custom windows container (Docker)?
This requires installing VS Code and that is OK but I'm looking for a solution that another user can get into with as few interruptions as possible
The idea is to ramp up the use of Python although, like I said, I don't expect Python to be serving any of the web content. It will be used to run in the background and to run scheduled jobs. What is the most robust and hopefully easiest way to add Python functionality to Azure (most importantly in a way to be able to trigger/use Python from an App Service running .NET?)? I've searched online and stack overflow so far with interesting finds but nothing to my liking.
For example, the following link discusses how to schedule WebJobs. I just created a manual one and when I called the webhook I got the message: "No route registered for '/api/triggeredwebjobs/TestPython/run'" How to schedule python web jobs on azure
The Docker method looks very promising, however, I'm looking for a simple solution as there is another person who will be involved in all of this and he's busy with other projects
Thank you very much!
I found a solution, though I'm open to more info. Like I mentioned in my post, I used the 'add extension' tool to add Python 3.6.4 to my Azure (installed in D:\home\python364x64).
Then I installed a bunch of packages via pip, these installed into D:\home\python364x64\Lib\site-packages.
I created a Python folder in webpages\Python where I put my scripts.
Finally, in ASP.NET I used the Diagnostics.Process call to run my code in ~\webpages\Python\somecode_2.py
The main issue is that Azure came with Python 2.7.15 installed. And for some reason when my Python code got executed it was using 3.4 (where that version came from beats me). So for each script, I had to create an _2.py version where I simply did the following in order to call the original script via Python 3.6.4. Looks a little nasty but it works. So like I said, I would welcome more info for ways to do this better...
--
import os<br>
os.system("D:\\home\python364x64\python.exe SomePython.py {0}".format(add arguments here)

How do I run a Django 1.6 project with multiple instances running off the same server, using the same db backend?

I have a Django 1.6 project (stored in a Bitbucket Git repo) that I wish to host on a VPS.
The idea is that when someone purchases a copy of the software I have written, I can type in a few simple commands that will take a designated copy of the code from Git, create a new instance of the project with its own subdomain (e.g. <customer_name>.example.com), and create a new Postgres database (on the same server).
I should hopefully be able to create and remove these 'instances' easily.
What's the best way of doing this?
I've looked into writing scripts using some sort of combination of Supervisor/Gnunicorn/Nginx/Fabric etc. Other options could be something more serious like using Docker or Vagrant. I've also looked into various PaaS options too.
Thanks in advance.
(EDIT: I have looked at the following services/things: Dokku (can't use Heroku due to data constraints), Vagrant (inc Puppet), Docker, Fabfile, Deis, Cherokee, Flynn (under dev))
If I was doing it (and I did a similar thing with a PHP application I inherited), I'd have a fabric command that allows me to provision a new instance.
This could be broken up into the requisite steps (check-out code, create database, syncdb/migrate, create DNS entry, start web server).
I'd probably do something sane like use the DNS entry as the database name: or at least use a reversible function to do that.
You could then string these together to easily create a new instance.
You will also need a way to tell the newly created instance which database and domain name they needed to use. You could have the provisioning script write some data to a file in the checked out repository that is then used by Django in it's initialisation phase.

How to use scripts to excecute django commands

Hi recently created my website in django. And I have used a web hosting provider who has django, python and my sql installed. But they do not have the ssh option or command prompt in their file manager. How can I use a script to excecute all the commands after uploading my site to the server .
I want file to be created like this updatedb.sh or updatedb.py .
Can anyone tell me how to use the scripts alone to host my django site live.
It is possible to have your Django views execute lines like:
import os
os.system("python manage.py syncdb")
In theory you could get the site working like that. However, this is a very poor strategy for deployment. Aside from the hassle of having os.system lines every time you want to do anything, what will you do if your entire site breaks? You'd be using convoluted hacks just to do the most basic maintenance.
If your web hosting provider truly doesn't support any kind of command line or even give you other options for setting up Django, it's time to find a new web hosting provider. I might recommend heroku, which supports Django and lets you deploy using git. (It is also free up to a certain amount of use).

How and where to deploy my Python and BottlePy application

Ok, so I made this application in Bottle that uses the NLTK package. It works fine on my computer which has all neccesary libraries installed, however, I can't get it to work on Google's App Engine. It gives these errors:
AttributeError: 'module' object has no attribute 'getuid'
I searched around and think this is a limitation of GAE, so I tried to use Alwaysdata and host my app there. However over there I have the problem that the YAML module is not installed. I tried to install it but access was denied.
creating /usr/local/lib/python2.6/site-packages/yaml
error: could not create '/usr/local/lib/python2.6/site-packages/yaml': Permission denied
So now I am stuck. This is the problem I walk into a lot. It all works fine on my computer, but then I can't get it to work online. Is this because of GAE limitations, alwaysdata limitations? So I guess I am asking where and how could I deploy best?
Is it more easy when I rent my own server and have full access there? Does that work as if it were my own computer and I can install everything?
Let me know if I need to provide more information, I'm pretty clueless.
I realise that you've already found an answer, but for other people looking for Python bottle hosting. PythonAnywhere has a quickstart option for deploying and hosting bottle apps now.
This is a three or four click wizard process that will have a barebones bottle application running in a 10 seconds. Letting you then build from there.
I've had great success running all different types of Python frameworks on WebFaction - http://www.webfaction.com/
Their support is awesome, instant replies to any problems I face. You get SSH access and can install your own modules, virtual-envs etc. You can run sites as a Custom Application listening on a port number, so you can basically run anything.
Here's a thread on how to setup a Bottle app with them: http://community.webfaction.com/questions/3998/how-to-setup-a-python-bottle-application
All that for $8.50/month if you pay a year upfront. http://www.webfaction.com/services/hosting
I can't recommend them enough.
Edit: Thought it wise to mention, I've written apps that use the NLTK and they've run on WebFaction with no troubles.

Categories