原文参考:http://oldj.net/article/python-upload-file-via-form-post/
首先要安装poster
import json
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
register_openers()
data,headers = multipart_encode({"package": open(filepath, "rb")})
request = urllib2.Request("http://yourip:yourport/path/upload?type=XX“,data,headers)
result = urllib2.urlopen(request).read()
jsonstr = json.loads(result)