互联网无处不在。即使是很小的,一次性使用的脚本都经常与远程服务进行交互以发送或接收数据。 Python有丰富的Web协议库,非常适合用于编程的基于Web服务的服务器和客户端编程。

urlparse处理URL字符串。
urllib和更新的urllib2可以访问web资源,但是urllib2更容易扩展且urllib2.Request可自定义请求头。HTTP POST发送二进制数据通常使用base64编码。
robotparser用于处理网站机器人。
使用BaseHTTPServer可自定义Web服务器,回话状态可以基于Cookie。
uuid用于生成资源标识符。
基于web的远程调用,json在客户端和服务器都使用。比如xmlrpclib和xmlrpclib。

python web 客户端测试 相关模块

web客户端

  • 标准模块:httplib
  • 标准模块:urllib
  • 标准模块:urllib2
  • 外部模块 mechanize:Stateful programmatic web browsing.
    • 最近更新:2011-03-31。
    • 月下载量:38441。
    • 从perl WWW::Mechanize而来,兼容urllib2。
  • 外部模块 spynner:Programmatic web browsing module with AJAX support for Python.
    • 最近更新:2013-07-16。
    • 月下载量:1192 。
    • 基于PyQT和WebKit,支持Javascript,AJAX,及其他WebKit可以处理的内容,比如 (Flash, SVG, …),利用了JQuery,用于在不适用GUI的情况模拟浏览器,适用于爬虫和验收测试。
  • 外部模块 PAMIE:基于pywin32,实现IE自动化
    • 最近更新:2009-03-06。
    • 版本:3.0
    • 月下载量:无。
    • 只适用于windows,主页http://sourceforge.net/projects/pamie,可能要翻墙。
  • WebTest:Helper to test WSGI applications –推荐
    • 最近更新:2014-01-23。
    • 版本:2.0.14
    • 月下载量:58134。
    • This wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.This provides convenient full-stack testing of applications written with any WSGI-compatible framework.Full docs can be found at https://webtest.readthedocs.org/en/latest/。
    • 下载:https://pypi.python.org/pypi/WebTest。
    • 主页: http://webtest.pythonpaste.org/。

参考资料

  • Web Programming in Python https://wiki.python.org/moin/WebProgramming
  • Web Site Test Tools and Site Management Tools http://www.softwareqatest.com/qatweb1.html

python 标准模块介绍 – Base16, Base32, Base64 数据编码

简介

功能:RFC 3548: Base16, Base32, Base64 数据编码。转换二进制数据为适合明文协议传输的 ASCII 序列。转换
8bits 为每个字节包含 6,5 或 4bits 的有效数据,比如 SMTP, URL 的一部分或者 HTTP POST 的一部分。参考:
RFC 3548。编码算法不同于 uuencode。
类型:标准库
相关模块:uu, binhex, uu, quopri

Base64 是一种基于 64 个可打印字符来表示二进制数据的表示方法。由于 2 的 6 次方等于 64,所以每 6
个位元为一个单元,对应某个可打印字符。三个字节有 24 个位元,对应于 4 个 Base64 单元,即 3 个字节
需要用 4 个可打印字符来表示。它可用来作为电子邮件的传输编码。在 Base64 中的可打印字符包括字母 A-
Z、a-z、数字 0-9,这样共有 62 个字符,此外两个可打印符号在不同的系统中而不同。之后在 6 位的前面补
两个 0,形成 8 位一个字节的形式。一些如 uuencode 的其他编码方法,和之后 binhex 的版本使用不同的
64 字符集来代表 6 个二进制数字,但是它们不叫 Base64。
Base64 常用于在通常处理文本数据的场合,表示、传输、存储一些二进制数据。包括 MIME 的
email,email via MIME,在 XML 中存储复杂数据。

Python Base64 模块提供了 RFC3548 中的数据编码和解码(转换二进制数据为适合明文协议传输的
ASCII 序列,如 RFC3548 中指定。该标准定义了 Base16,Base32 和 Base64 算法,编码和解码的任意二进制字符串转换为文本字符串,这样就可以通过电子邮件安全发送,作为网址的一部分,或包含在 HTTP POST 请求中。
Base64 模块提供两个接口。新式接口支持使用三个字母的编码和解码的字符串对象。传统接口提供了编
码和解码文件对象和字符串,但只使用了标准的 Base64 字母。传统接口这里不做介绍。
base64、 base32、 base16 可以分别编码转化 8 位字节为 6 位、 5 位、 4 位。 16,32,64 分别表示用多少个字
符来编码。
更多 base64 的资料,参见
http://zh.wikipedia.org/wiki/Base64,http://tools.ietf.org/html/rfc822,http://tools.ietf.org/html/rfc14
21,http://tools.ietf.org/html/rfc2045。

快速入门

请看 python 模块介绍中的实例:

1234567 >>> import base64>>> encoded = base64.b64encode(\’data to be encoded\’)>>> encoded\’ZGF0YSB0byBiZSBlbmNvZGVk\’>>> data = base64.b64decode(encoded)>>> data\’data to be encoded\’

base64.b64encode(s[, altchars]):使用 Base64 编码字符串。s 是要编码的字符串。altchars 是用来替换+和/的字符串,它们在 url 和文件系统中它们有特殊含义,通常需要替换。
base64.b64decode(s[, altchars]): 解码 Base64 编码的字符串。s 为要解码的字符串。altchars 和b64encode 相同。
• base64.standard_b64encode ( s ) : 参考 b64encode。
• base64.standard_b64decode ( s ) :参考 b64decode。

Base64 编码解码

Base64 编码解码

123456789101112131415161718192021222324 #!/usr/bin/env python# encoding: utf-8## Copyright (c) 2008 Doug Hellmann All rights reserved.#\”\”\”\”\”\”__version__ = \”$Id$\”#end_pymotw_headerimport base64import textwrap# Load this source file and strip the header.with open(__file__, \’rt\’) as input:raw = input.read()initial_data = raw.split(\’#end_pymotw_header\’)[1]encoded_data = base64.b64encode(initial_data)num_initial = len(initial_data)# There will never be more than 2 padding bytes.padding = 3 (num_initial % 3)print \’%d bytes before encoding\’ % num_initialprint \’Expect %d padding bytes\’ % paddingprint \’%d bytes after encoding\’ % len(encoded_data)printprint encoded_data

➢执行结果thon base64_b64encode.py

1234567 $ python base64_b64encode.py168 bytes before encodingExpect 3 padding bytes224 bytes after encodingCgppbXBvcnQgYmFzZTY0CmltcG9ydCB0ZXh0d3JhcAoKIyBMb2FkIHRoaXMgc291cmNlIGZpbGUgYW5kIHN0cmlwIHRoZSBoZWFkZXIuCndpdGggb3BlbihfX2ZpbGVfXywgJ3J0JykgYXMgaW5wdXQ6CiAgICByYXcgPSBpbnB1dC5yZWFkKCkKICAgIGluaXRpYWxfZGF0YSA9IHJhdy5zcGxpdCgn

Base64 编码的 4 个字节对应实际的 3 个字节,不足四个字节时,后面部分通常用等号填充。极端的情况下,
一个字节需要用 4 个 Base64 编码来表示。

1234 >>> import base64>>> encoded = base64.b64encode(\’a\’)>>> encoded\’YQ==\’

Base64 解码参见快速入门部分介绍。

URL-Safe

•base64.urlsafe_b64encode(s):
•base64.urlsafe_b64decode(s):
Base64 默认会使用+和/, 但是这 2 个字符在 url 中也有特殊含义。使用 urlsafe 可以解决这个问题。 +替换为-,
/替换为_。

123456789 import base64encodes_with_pluses = chr(251) + chr(239)头。HTTP POST发送二进制数据通常使用base64编码。
robotparser用于处理网站机器人。
使用BaseHTTPServer可自定义Web服务器,回话状态可以基于Cookie。
uuid用于生成资源标识符。
基于web的远程调用,json在客户端和服务器都使用。比如xmlrpclib和xmlrpclib。

python web 客户端测试 相关模块

web客户端

  • 标准模块:httplib
  • 标准模块:urllib
  • 标准模块:urllib2
  • 外部模块 mechanize:Stateful programmatic web browsing.
    • 最近更新:2011-03-31。
    • 月下载量:38441。
    • 从perl WWW::Mechanize而来,兼容urllib2。
  • 外部模块 spynner:Programmatic web browsing module with AJAX support for Python.
    • 最近更新:2013-07-16。
    • 月下载量:1192 。
    • 基于PyQT和WebKit,支持Javascript,AJAX,及其他WebKit可以处理的内容,比如 (Flash, SVG, …),利用了JQuery,用于在不适用GUI的情况模拟浏览器,适用于爬虫和验收测试。
  • 外部模块 PAMIE:基于pywin32,实现IE自动化
    • 最近更新:2009-03-06。
    • 版本:3.0
    • 月下载量:无。
    • 只适用于windows,主页http://sourceforge.net/projects/pamie,可能要翻墙。
  • WebTest:Helper to test WSGI applications –推荐
    • 最近更新:2014-01-23。
    • 版本:2.0.14
    • 月下载量:58134。
    • This wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.This provides convenient full-stack testing of applications written with any WSGI-compatible framework.Full docs can be found at https://webtest.readthedocs.org/en/latest/。
    • 下载:https://pypi.python.org/pypi/WebTest。
    • 主页: http://webtest.pythonpaste.org/。

参考资料

  • Web Programming in Python https://wiki.python.org/moin/WebProgramming
  • Web Site Test Tools and Site Management Tools http://www.softwareqatest.com/qatweb1.html

python 标准模块介绍 – Base16, Base32, Base64 数据编码

简介

功能:RFC 3548: Base16, Base32, Base64 数据编码。转换二进制数据为适合明文协议传输的 ASCII 序列。转换
8bits 为每个字节包含 6,5 或 4bits 的有效数据,比如 SMTP, URL 的一部分或者 HTTP POST 的一部分。参考:
RFC 3548。编码算法不同于 uuencode。
类型:标准库
相关模块:uu, binhex, uu, quopri

Base64 是一种基于 64 个可打印字符来表示二进制数据的表示方法。由于 2 的 6 次方等于 64,所以每 6
个位元为一个单元,对应某个可打印字符。三个字节有 24 个位元,对应于 4 个 Base64 单元,即 3 个字节
需要用 4 个可打印字符来表示。它可用来作为电子邮件的传输编码。在 Base64 中的可打印字符包括字母 A-
Z、a-z、数字 0-9,这样共有 62 个字符,此外两个可打印符号在不同的系统中而不同。之后在 6 位的前面补
两个 0,形成 8 位一个字节的形式。一些如 uuencode 的其他编码方法,和之后 binhex 的版本使用不同的
64 字符集来代表 6 个二进制数字,但是它们不叫 Base64。
Base64 常用于在通常处理文本数据的场合,表示、传输、存储一些二进制数据。包括 MIME 的
email,email via MIME,在 XML 中存储复杂数据。

Python Base64 模块提供了 RFC3548 中的数据编码和解码(转换二进制数据为适合明文协议传输的
ASCII 序列,如 RFC3548 中指定。该标准定义了 Base16,Base32 和 Base64 算法,编码和解码的任意二进制字符串转换为文本字符串,这样就可以通过电子邮件安全发送,作为网址的一部分,或包含在 HTTP POST 请求中。
Base64 模块提供两个接口。新式接口支持使用三个字母的编码和解码的字符串对象。传统接口提供了编
码和解码文件对象和字符串,但只使用了标准的 Base64 字母。传统接口这里不做介绍。
base64、 base32、 base16 可以分别编码转化 8 位字节为 6 位、 5 位、 4 位。 16,32,64 分别表示用多少个字
符来编码。
更多 base64 的资料,参见
http://zh.wikipedia.org/wiki/Base64,http://tools.ietf.org/html/rfc822,http://tools.ietf.org/html/rfc14
21,http://tools.ietf.org/html/rfc2045。

快速入门

请看 python 模块介绍中的实例:

1234567 >>> import base64>>> encoded = base64.b64encode(\’data to be encoded\’)>>> encoded\’ZGF0YSB0byBiZSBlbmNvZGVk\’>>> data = base64.b64decode(encoded)>>> data\’data to be encoded\’

base64.b64encode(s[, altchars]):使用 Base64 编码字符串。s 是要编码的字符串。altchars 是用来替换+和/的字符串,它们在 url 和文件系统中它们有特殊含义,通常需要替换。
base64.b64decode(s[, altchars]): 解码 Base64 编码的字符串。s 为要解码的字符串。altchars 和b64encode 相同。
• base64.standard_b64encode ( s ) : 参考 b64encode。
• base64.standard_b64decode ( s ) :参考 b64decode。

Base64 编码解码

Base64 编码解码

123456789101112131415161718192021222324 #!/usr/bin/env python# encoding: utf-8## Copyright (c) 2008 Doug Hellmann All rights reserved.#\”\”\”\”\”\”__version__ = \”$Id$\”#end_pymotw_headerimport base64import textwrap# Load this source file and strip the header.with open(__file__, \’rt\’) as input:raw = input.read()initial_data = raw.split(\’#end_pymotw_header\’)[1]encoded_data = base64.b64encode(initial_data)num_initial = len(initial_data)# There will never be more than 2 padding bytes.padding = 3 (num_initial % 3)print \’%d bytes before encoding\’ % num_initialprint \’Expect %d padding bytes\’ % paddingprint \’%d bytes after encoding\’ % len(encoded_data)printprint encoded_data

➢执行结果thon base64_b64encode.py

1234567 $ python base64_b64encode.py168 bytes before encodingExpect 3 padding bytes224 bytes after encodingCgppbXBvcnQgYmFzZTY0CmltcG9ydCB0ZXh0d3JhcAoKIyBMb2FkIHRoaXMgc291cmNlIGZpbGUgYW5kIHN0cmlwIHRoZSBoZWFkZXIuCndpdGggb3BlbihfX2ZpbGVfXywgJ3J0JykgYXMgaW5wdXQ6CiAgICByYXcgPSBpbnB1dC5yZWFkKCkKICAgIGluaXRpYWxfZGF0YSA9IHJhdy5zcGxpdCgn

Base64 编码的 4 个字节对应实际的 3 个字节,不足四个字节时,后面部分通常用等号填充。极端的情况下,
一个字节需要用 4 个 Base64 编码来表示。

1234 >>> import base64>>> encoded = base64.b64encode(\’a\’)>>> encoded\’YQ==\’

Base64 解码参见快速入门部分介绍。

URL-Safe

•base64.urlsafe_b64encode(s):
•base64.urlsafe_b64decode(s):
Base64 默认会使用+和/, 但是这 2 个字符在 url 中也有特殊含义。使用 urlsafe 可以解决这个问题。 +替换为-,
/替换为_。

12345