[Python 2.7] Hello World CGI HTTP Server

# CGI HTTP server

## Getting Started

Python 2.x is preferred to this simple demo. I‘m using Python 2.7 over windows.

https://docs.python.org/2.7/library/cgihttpserver.html

https://docs.python.org/2.7/library/cgi.html

## Starting a CGIHTTPServer

$ python -m CGIHTTPServer 8000

Serving HTTP on 0.0.0.0 port 8000 ...

## CGI Script, Hello World

$ mkdir cgi-bin/

$ vim cgi-bin/index.py

print "Content-Type: text/html" # HTML is following

print # blank line, end of headers

print "<TITLE>CGI script output</TITLE>"

print "<H1>This is my first CGI script</H1>"

print "Hello, world!"

## Access

Browser the following link and a web page will return.

http://localhost:8000/cgi-bin/index.py

This is my first CGI script

Hello, world!

版权声明:本文博主原创文章,博客,未经同意不得转载。

时间: 2024-08-26 07:44:51

[Python 2.7] Hello World CGI HTTP Server的相关文章

Python Socket,How to Create Socket Server? - 网络编程实例

文章出自:Python socket – network programming tutorial by Silver Moon 原创译文,如有版权问题请联系删除. Network programing in Python: Part2: Programing sockets servers. 在所有的通信实例中,都分为Client 和Server. 其中:Client是请求的发起点,Server是使用Socket接收传入的值并且提供返回数据. Server的职能如下: 1>.创建/打开一个so

Python中socket经ssl加密后server开多线程

        前几天手撸Python socket代码,撸完之后经过ssl加密,确保数据的安全,外加server端开启多线程保证一个客户端连接有一个线程来服务客户端,走了不少的弯路,网上的信息啥的要么有ssl没有服务端的多线程,要不只有多线程没有加ssl加密,对于新手做这种需求还是有些困难的,这里,经过我!李帅帅的实践得出各种版本的代码以及最终终结版的代码,话说妇联4都他娘的药终结了,还有几天就上映了,说票挺贵的,这他娘的看个屁,大不了过半个月在啃,不知道黑寡妇最后咋样了,啧啧,挺好的一个姑娘

python,socket网络编程,最简单的server端和client端代码

python网络编程三要素:网络地址,端口号,协议 知识点:conn代表的是客户端的socket对象. 下面的server.py和client.py小程序,实现了最简单的socket通信功能. #server.py import socket sk = socket.socket() address = ('127.0.0.1',8080) sk.bind(address) sk.listen(3) print('waitting......') conn,addr = sk.accept()

通读Python官方文档之cgi

cgi 通用网关接口 前驱知识 网关协议学习:CGI.FastCGI.WSGI 简单点说: web服务器接受请求,启动CGI:CGI接受请求,处理,返回给服务器:服务器返回给用户 cgi效率不高,每次都要fork一个新进程出来 WCGI,Python架设的一个桥,连接了服务器和web框架,相当将cgi的连接功能独立了出来,并把处理功能留给了web框架 简介 CGI脚本由HTTP服务器启动,通常用来处理用户通过<FROM>提交的数据. 通常,CGI脚本位于服务器的专门的cgi-bin目录下.HT

【Python】 做一个简单的 http server

# coding=utf-8 ''' Created on 2014年6月15日 @author: Yang ''' import socket import datetime # 初始化socket s = socket.socket() # 获取主机名, 也能够使用localhost # host = socket.gethostname() host = "localhost" # 默认的http协议端口号 port = 80 # 绑定serversocket的ip和端口号 s.

Python与数据库[1] -&gt; 数据库接口/DB-API -&gt; SQL Server 适配器

SQL_Server适配器 / SQL_Server Adapter 1 环境配置 / Environment Configuration 安装SQL_Server的Python适配器包 pip install pymssql Note: 此处采用远程数据库服务器,因此未安装本地SQL_Server 2 SQL_Server实例 / SQL_Server Examples 由于远程数据库账号仅具有读取权限,因此此处示例基本以读取为主. 查看数据库 / Show Database 利用适配器的基本

Python读取配置文件,并连接数据库SQL Server

用配置文件保存固定的连接数据,改的话比较方便. 1.新建一个配置文件:SQlconfig.config,以数据库为例. 内容如下,当然也可以添加多个 [Database1] database=db_test host=test.sqlserver.rds.alincs.com,3433 user=qhlt_just pwd=zHi4M63wIddlSDK2nY [Database2] database=db_test host=test.sqlserver.rds.alincs.com,3433

Python:用 peewee 框架连接 SQL Server

Peewee 默认支持 Sqlite.MySQL.PostgreSQL 三种数据库,如果要使用其他数据库,需要同时安装扩展库.比如 SQL Server,需要安装 peewee-mssql. 但是安装 peewee-mssql 后却发现运行报错,而且是 import peewee-mssql 的时候就报错了.查看一下 peewee_mssql.py 源文件,发现 import peewee 的时候报错了,其中很多类在 peewee 中没有,估计是版本问题了.peewee-mssql 目前最新版本

使用python获得activemq信息(通过http://server:8161/

1 # encoding=utf-8 2 import urllib2 3 import cookielib 4 # from BeautifulSoup import BeautifulSoup 5 from bs4 import BeautifulSoup 6 import re 7 queue_url = "http://192.168.16.218:8161/admin/queues.jsp" 8 9 def MQBrowser(url): 10 login_page = qu