#!/bin/pythoncodeing 指定本文編碼
#coding: utf-8
# -*- coding: utf-8 -*-
import urllib
str = "測試utf8 編解碼"
str_en = urllib.quote(str).encode('utf-8')
print str_en
print urllib.unquote(str_en)
其他應用
from urllib import quote, unquote
input = u"http://test.net/~admin"
input = input.encode('utf8')
print quote(input) # http%3A//test.net/%7Eadmin
print quote(input, '') # http%3A%2F%2Ftest.net%2F%7Eadmin
print quote(input, '~/') # http%3A//test.net/~admin