Debugging server script like python? - python

I'm new to 'network' programming. I've done throughout the Google app engine tutorial and I'm trying to make my own application which is guestbook. It has a server script on Google app engine and client app is running on iPhone.
But how do I check if the server is received my message from iPhone?
or How do I debug the script I wrote on server side? (it's an python script)
I want to make sure the data is in right format and other stuff.
Please somebody give me a link if there's good tutorial or good place to start. thanks.

In your code you should be using tons of logging calls. In the app engine dashboard for your app there is an option to view logs, and all of your logging calls will show up in there (and can be filtered in various ways).
There are also ways to run dev_appserver.py and debug locally using software like PyDev, but you'd have to make your iPhone app send its messages to the address of your local server.

Related

Dash/Flask - Deployment of an application on my own server

I am a newbie in web development, I am an energy engineering student trying to make a project, so I apologize if I say something weird.
I've made an application using Dash (python). And now, I would like to deploy that app in my server. I have a remote server (debian, adress.com, IP, opened ports: 80 and 443...) with my ssh public key and all the required stuff.
I have read all the official documentation in the plotly dash page, and also in flask's, but I dont understand very well the thing. I need either Heroku, OpenShift... And I dont understand very well how them work.
Could you please recommend me an easy tutorial (for dummies!) or give me advices/examples about the deployment? I would really apreciate I've searched the Internet a lot, but I can't figure it out.
You describe two options:
1. using your own server to host your app and
2. using a service which will host your app (heroku, etc.)
Using your own server to host your app
You need to decide for a web server, which is serving your page on your server. A host will not magically answer on any port. There is for example apache, nginx, etc... After having chosen one, you need to find a tutorial: how to run your flask app on [yourwebserver] or something like that.
Suppose you have chosen apache, you will find something like this:
https://jackhalpinblog.wordpress.com/2016/08/27/getting-your-python-3-flask-app-to-run-on-apache/
(In this case, you will have to figure out how to run your flask app with python3 instead of python2, if you are running debian)
When your page serves your page, you need an ssl certificate in order to make use of your domain. An easy way of doing this is https://letsencrypt.org/getting-started/ (there are probably other similar services)
Using a service, which will host your app for you (heroku, etc.)
Alternatively do not host you app on your own server, but on heroku, aws, gcd, etc., in my opinion this is much easier than hosting it on your own server. The documentation on hosting service websites is normally very good.
For heroku a good starting point would be here:
https://devcenter.heroku.com/articles/getting-started-with-python. Nevertheless the other services are easy to use as well, i just use this as an example.

Setting up a sever on Google Cloud with Postgresql database?

I've been trying for about two weeks now to set up a server for a completed Django app on the google cloud shell. All of the documentation for gcloud is confusing and sends me to several different pages for one task and it is very hard to keep track of what to do. Sites like digitalocean, which is useful for Django program setup, doesn't work on gcloud. I haven't figured out a way to connect a postgres VM to my program through the cloud shell despite having the server running. I am very lost in setting this up. Could someone please help me set up my Django app? It runs perfectly on localhost but when trying to implement it into the google cloud nothing works.
I've done the django-gcloud tutorial already and set up a simple site just by importing the code from google, which doesn't help because all it does is import a completed app and you just type in "gcloud app deploy" which doesn't explain how to set it up so that you can do that.
My program uses python 3, DjangoRestFramework, and Celery. The database is Postgresql.
My full module list is:
Django-1.11.2 amqp-2.1.4 astroid-1.5.3 billiard-3.5.0.2 celery-4.0.2 djangorestframework-3.6.3 isort-4.2.15 kombu-4.0.2 lazy-object-proxy-1.3.1 mccabe-0.6.1 pep8-1.7.0 psycopg2-2.7.1 pylint-1.7.2 pytz-2017.2 six-1.10.0 vine-1.1.3 wrapt-1.10.10

How to deploy a bottle webapp in production?

I wrote a little bottle web application, played around with setup.py, and I'm ready to deploy.
I had two questions:
How do I deploy this new web app in production? Do I need a a webserver or reverse proxy? Can my main.py be run as a service? How is this typically done?
My web app uses a mongodb backend. Is there a way to package that with my application or to require it / look for it / alert the user when the installer runs? How is this typically done?
Pythonanywhere allows you for free to test/deploy a Bottle app with Pymongo driver. This is one of the webhostings which is python-deployers friendly... If you need something for a serious trafic, then you have to consider a paid programm or your own (virtual/dedicated) hosted server.
I ran my Bottle applications on OpenShift. There's a quickstart template on GitHub for getting a Bottle application online. You could just copy their directory structure and files, add your own, and send it all to the git repository that is created for you. OpenShift uses git when it comes to development, so if you ever make any changes, you just need to commit and push them to the server again.
MongoDB and RockMongo (a GUI for managing your MongoDB database, similar to phpMyAdmin for MySQL) are built in. You get three 'gears' or instances to work with, so the Bottle application will be one, with MongoDB and RockMongo included. You just have to enable them.

Execute python script in localhost

I have downloaded and installed python on my PC. I am learning python at this moment so I am a beginner.
Is there anyway I could execute python scripts in localhost (Apache) and view them in a web browser as we do with PHP? I am executing the python scripts from CLI at this moment.
Although there are multiple solutions, I would take a look at mod_python. Unfortunately, in my experience it is not the easiest thing in the world to set up and requires making changes to httpd.conf, but this tutorial is helpful (and gives some examples).
Google App Engine SDK for Python includes a local web server application that simulates the App Engine environment. It allows for instant server script changes by just saving the file and refreshing the browser.
The development tutorial is here
Once you have your web site working locally, it is easy to deploy it live on Google's App Engine servers.

how to write a client/server app in heroku

I am quite new to heroku and I reached a bump in my dev...
I am trying to write a server/client kind of application...on the server side I will have a DB(I installed postgresql for python) and I was hoping I could reach the server, for now, via a python client(for test purposes) and send data/queries and perform basic tasks on the DB.
I am using python with Heroku, I manage to install the DB and it seems to be working(i.e i can query, insert, delete, etc...)
now all i want is to write a server(in python) that would be my app and would listen on a port and receive messages and then perform whatever tasks it is asked to do...I tought about using sockets for this and have managed to write a basic server/client locally...however when I deploy the app on heroku i cannot connect to the server and my code is basically worthless
can somebody plz advise on the basic framework for this sort of requirements...surely I am not the first guy to want to write a client/server app...if you could point to a tutorial/doc i would be much obliged.
Thx
Heroku is for developing Web (HTTP, HTTPS) applications. You can't deploy code that uses socket to Heroku.
If you want to run your app on Heroku, the easier way is to use a web framework (Flask, CherryPy, Django...). They usually also come with useful libraries and abstractions for you to talk to your database.

Categories