---
title: "Python3调用hessian"
author: "youanyyou"
date: "2015-07-24T16:52:24Z"
tags: []
categories: ["编程语言"]
slug: "python3-hessian"
draft: false
lastmod: "2015-07-24T16:52:24Z"
id: 2230020
url: "https://itlol.iteye.com/blog/2230020"
---

领导派了个任务，实现服务器日志文件调用hessian接口保存到数据库

研究了半天python调用hessian的办法

 

首先使用hessian for python的链接：

http://hessian.caucho.com/#Python

引入进来后各种报错，各种崩溃啊

[hessianlib.py](http://hessian.caucho.com/download/hessianlib.py)在官网上还是2007的版本，估计不支持python3??

 

然后寻找python3调用hessian的资料，关于python2转换成3的语法，使用：

2to3.py在python目录：C:\\Python\\Tools\\Scripts\\2to3.py

python 2to3.py -w [hessianlib.py](http://hessian.caucho.com/download/hessianlib.py)

运行后，转换部分不成功，后来还是放弃了这个想法

 

后来上谷歌一直寻找方案，最终在不断地研究下找到了突破口，原来关于hessian的python实现，已经转交给mustaine项目来处理，并且给出了google code地址：http://code.google.com/p/mustaine/

接下来安装pyhessian和six

pyhessian下载：http://code.google.com/p/mustaine/

six下载：https://pypi.python.org/pypi/six

下载后使用命令安装：

python C:\\Users\\Admin\\Desktop\\python-hessian-master\\setup.py install

python C:\\Users\\Admin\\Desktop\\six-1.9.0\\setup.py install

安装后six没问题了，可pyhessian还需要把目录python-hessian-master\\**pyhessian**复制到C:\\Python\\Lib\\site-packages\\**pyhessian**

 

引用pyhessian：

from pyhessian.client import HessianProxy

 

测试pyhessian成功：

params = {"p1":"101", "p2":"102"}

service = HessianProxy("http://192.168.1.1:8080/test/services/test.hessian")

result = service.test(params)

print(result.value)