One liner webServer (with CGI) in python

Thing you want to do

I want to create a simple web server and check the operation of my application. (I want something like DummyServer)

HowTo

What to use?

There seemed to be various ways to do it, but python seems to be quick, so I adopted python (Quick => linux comes standard)

Various = nc command, php, ruby, etc. are also possible.

Try

Create access destination

(It can be anywhere, but I tried it with tmp for the time being)
cd /tmp 

(Since I want to access cgi this time, create the following dir (cgi by default)-It seems to be useless unless it is named bin or htbin))
mkdir cgi-bin

(Try to place a script)

vi hoge.py

The contents are ↓↓↓

cat hoge.py 
#!/usr/bin/env python
# -*- coding: utf-8 -*-

hoge="Welcome to one liner."

print """Content-Type: text/html

<html>
<body>
<h2>{0}</h2>
</body>
</html>
""".format(hoge)

I'll give you execute permission: fist:

$ chmod 655 hoge.py

Start webServer

$ sudo python -m CGIHTTPServer 1234
Serving HTTP on 0.0.0.0 port 1234 ...

access! : punch:

$ curl localhost:1234/cgi-bin/hoge.py
<html>
<body>
<h2>Welcome to one liner.</h2>
</body>
</html>


Access log is also available

$ sudo python -m CGIHTTPServer 1234
Serving HTTP on 0.0.0.0 port 1234 ...
localhost - - [03/Dec/2014 19:06:01] "GET / HTTP/1.1" 200 -
localhost - - [03/Dec/2014 19:06:06] "GET /cgi-bin/hoge.py HTTP/1.1" 200 -

Summary: sparkles:

Isn't it really easy! ?? It is troublesome to set up a file server in-house, I wrote it at the beginning, but for the time being, how to use it like a Dummy Server (stub), if you want to move something, it is quite Isn't it easy to use?

Recommended Posts

One liner webServer (with CGI) in python
One liner in Python
CGI server (1) python edition in one line
python Zundko One Liner
One liner that outputs multiplication tables in Python
One liner to 100% CPU1 core usage in Python
Scraping with selenium in Python
Fizzbuzz in Python (in one line)
curl -I python one liner
Working with LibreOffice in Python
Scraping with chromedriver in python
Debugging with pdb in Python
DMD in Python one dimension
Scraping with Selenium in Python
One liner that outputs 1000000 digits of pi in Python
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
[Python] Plotly draws Pandas dataframes in one shot with Cufflinks
Automatically generate frequency distribution table in one shot with Python
Things to keep in mind when using cgi with python.
Number recognition in images with Python
Make python segfault in one line
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
Scraping with Selenium in Python (Basic)
CSS parsing with cssutils in Python
Numer0n with items made in Python
Open UTF-8 with BOM in Python
Use rospy with virtualenv in Python3
Heatmap with Dendrogram in Python + matplotlib
Read files in parallel with Python
Password generation in texto with python
Use OpenCV with Python 3 in Window
Until dealing with python in Atom
Get started with Python in Blender
Working with DICOM images in Python
How to display legend marks in one with Python 2D plot
How to calculate "xx time" in one shot with Python timedelta
Handle multiple python versions in one jupyter
Write documentation in Sphinx with Python Livereload
Get additional data in LDAP with python
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Try logging in to qiita with Python
Stress Test with Locust written in Python
Exclusive control with lock file in Python
Device monitoring with On-box Python in IOS-XE
Try working with binary data in Python
Draw Nozomi Sasaki in Excel with python
Tips for dealing with binaries in Python
Display Python 3 in the browser with MAMP
Page cache in Python + Flask with Flask-Caching
Post Test 3 (Working with PosgreSQL in Python)
How to work with BigQuery in Python
Playing card class in Python (with comparison)
Dealing with "years and months" in Python
Process multiple lists with for in Python
Replace non-ASCII with regular expressions in Python
Connect with mysql.connector with ssh tunnel in Python 3.7
Get Started with TopCoder in Python (2020 Edition)
Decompose command arguments in one line in Python