Trying to use python on a server - python

I am using pythonanywhere.com and trying to run an app that I made for twitter that uses tweepy but it keeps saying connection refused or failed to send request. Is there any way to run a python app online easily that sends requests?

Pythonanywhere requires a premium account for web access.
You can create a limited account with one web app at your-username.pythonanywhere.com, restricted Internet access from your apps, low CPU/bandwidth. It works and it's a great way to get started!
Get a premium account:
$5/month
Run your Python code in the cloud from one web app and the console
A Python IDE in your browser with unlimited Python/bash consoles
One web app with free SSL at
your-username.pythonanywhere.com
Enough power to run a typical 50,000 hit/day website.
(more info)
3,000 CPU-seconds per day
(more info)
512MB disk space
That said, I'd just set it up locally if its for personal use and go from there.

You will need a server that has a public IP.
You have a few options here:
You can use a platform-as-a-service provider like Heroku or AWS Elastic Beanstalk.
You can get a server online on AWS, install your dependencies and use it instead.
As long as you keep your usage low, you can stay withing the free quotas for these services.

Related

What is the most efficient way to create an https endpoint for existing Teams chatbot (python)?

I've recently got a Teams chatbot working. The chatbot is written in Python and is based on code samples provided on the Microsoft Bot Builder GitHub (link below). As suggested in the code samples, I started off with using ngrok for testing. So the setup currently is like this:
When someone sends a message to the Bot, the message is routed to Azure Bot Service.
Asure Bot Service is configured to send traffic to an AWS EC2 instance which has ngrok running along with the python app. Ngrok endpoint: https://xyz.ngrok.io.
Python app on the EC2 instance responds back to the user (python app > ngrok > Azure Bot Service > Microsoft Teams).
The above setup works well but now I'd like to remove the ngrok intermediary. When I realize that Azure Bot Service only allows https endpoint and that my ngrok was doing the ssl. Looks like the code samples provided was from before Azure made it mandatory for Bot Service to only use https endpoint. Could anyone please advise what's the best way to move forward in my situation? I understand that re-architecture using api gateway/lambda would make it easier but I'd like to keep the current architecture for now. Is my only option to create certificates (which is new to me)? Appreciate any guidance here.
https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/02.echo-bot
You can definitely remove ngrok, and it cetainly should be removed - it's only meant for local workstation development, and one of the main reasons is to support SSSL/TLS as httpS is -required- for bots. You'll need to spend some time figuring out how to get certificates working on your EC2, as a result, but it's probably really good experience as httpS is mandated for various things these days. Also, although I don't have any personal experience with EC2, these days I can't imagine it's hard to add certificates.

Python - Deploying Voilà ways

I have created a python notebook with many widgets connected to many dataframes and I can deploy it fine with Voilà on my local host. I would like to understand what is in the simplest way possible I can share the link with people on my internal network and also outside.
I read my articles suggesting to use Heroku, Binder (with GitHub), Google App Engine, PythonAnywhere...
So my question is what do you suggest for my needs? I would like to keep the interface generated with Voilà and I was hooping not to share it public or at least not to everyone.
Thank you
There are services which allow you to 'essentially' put your localhost on the web i.e. they allow people to remotely access a website hosted as localhost on your machine. I have personally used https://ngrok.io. I've also heard of localhost.run which is a recently launched service. With these services, you will get a URL that you can now send to the folks who you would like to access your service. If you do this, your local machine (the one hosting the service) has to be on.
You can also go with the option of deploying to a host like Google App Engine (GAE), PythonAnywhere, Heroku, etc. But you should add some form of authentication so that access is only granted to those who provide that authentication.

Implementing web service with python on a virtual AWS instance

I need to implement a simple web service in python - it's my first experience with web services and REST APIs so I want to undertand what environment and tools would fit my needs. In my web service, I need to read some data from a database, do some simple logic, and support a GET call from another application (qualtrics).
I read and implemented a simple test web service with python using some useful blogs such as: Building a Basic RestFul API in Python | Codementor
but I need a real server so that I could call the API from external applications.
As I'm looking for a long term solution, I thought that using AWS EC2 instance may be a good solution for a server. I tried to implement it using some guidelines in blogs such as: Deploy a Flask app on AWS EC2 | Codementor
However, as I'm new to this and encountered some implementation/editing errors (e.g. handling of the wsgi file) and as I'm a windows person and the ubuntu stuff are not always easy to get used to, I was wondering what is the best framework for my needs?
Is there any recomended flow in which I'll be able to implement my simple python code and connect it to a small server (either AWS EC2 instance or any other recomended one) in a more convenient way?
Another important note - I will need to run it only from time to time, this web server and web service should not be contantly live (that's why I thought that aws virtual instance would fit best).
To begin, my recommendation would be to look at Elastic Beanstalk, Fargate and API Gateway with Lambda.
You can use Elastic Beanstalk to easliy provision out-of-the-box AWS environment to host your python app in Flask with minimal configurations required:
Deploying a flask application to Elastic Beanstalk.
The other thing to consider would be to develop your python app as a docker container using, e.g., tiangolo/uwsgi-nginx-flask as the base image. This would allow you to easily work with in on your localhost, and then just move your image to AWS for hosting.
You can host it on Fargate to save time on configuring container instances, or on Beanstalk as well which also supports docker.
Yet other choice is to go fully serverless and develop your Python REST api using API Gateway and lambda.

Understanding each component of a web application architecture

Here is a scenario for a system where I am trying to understand what is what:
I'm Joe, a novice programmer and I'm broke. I've got a Flask app and one physical machine. Since I'm broke, I cannot afford another machine for each piece of my system, thus the web server, application and database all live on my one machine.
I've never deployed an app before, but I know that a server can refer to a machine or software. From here on, lets call the physical machine the Rack. I've loaded an instance of MongoDB on my machine and I know that is the Database Server. In order to handle API requests, I need something on the rack that will handle HTTP/S requests, so I install and run an instance of NGINX on it and I know that this is the Web Server. However, my web server doesnt know how to run the app, so I do some research and learn about WSGI and come to find out I need another component. So I install and run an instance of Gunicorn and I know that this is the WSGI Server.
At this point I have a rack that is home to a web server to handle API calls (really just acts as a reverse proxy and pushes requests to the WSGI server), a WSGI server that serves up dynamic content from my app and a database server that stores client information used by the app.
I think I've got my head on straight, then my friend asks "Where is your Application Server?"
Is there an application server is this configuration? Do I need one?
Any basic server architecture has three layers. On one end is the web server, which fulfills requests from clients. The other end is the database server, where the data resides.
In between these two is the application server. It consists of the business logic required to interact with the web server to receive the request, and then with the database server to perform operations.
In your configuration, the WSGI serve/Flask app is the application server.
Most application servers can double up as web servers.

Hosting Python Twilio server online?

I'm trying to complete an iOS Swift app that send SMS with custom body. I found the following tutorial and it worked for me, however, it requires having a running python server. Is there any site that you recommend where I can host the python server and access it remotely through the web? Are there any alternatives for doing this by skipping the python server and directly sending an HTTP request from the app?
Note: This is in iOS 11 and Xcode 9 with latest version of Swift. I am also a beginner with HTTP requests and server stuff.
Your best bet is to host it through heroku (initially). the pricing structure is built on activity (great if you are testing and need hosting to be as inexpensive as possible), auto recognition of python code, and they give you a url that you can access remotely (i.e. someapp.heroku.com) that should allow you to access in your app.

Categories