【介绍】
EPPY 是 Python 环境下的一款 EPP 客户端。用于域名注册商和域名注册局之间的网络通信。
特性:
1. 标准 Python 日志
2. 支持 TLS/SSL support
3. 测试案例包
【安装】
环境:python 2.7.5
pip 模式:
网址:https://pypi.org/project/EPP/
注意:pypi.org网站上的eppy是另一款程序
pip install EPP==0.6
源码模式:
源码:https://github.com/cloudregistry/eppy
pip install -e git+https://github.com/cloudregistry/eppy.git#egg=eppy
【使用】
文档:https://github.com/cloudregistry/eppy/blob/master/README.rst
测试:https://github.com/cloudregistry/eppy/tree/master/eppy/load_test
客户端使用SSl登录EPP服务器:
>>> from eppy.client import EppClient
>>> client = EppClient(ssl_keyfile='client.key', ssl_certfile='client.pem')
>>> client.connect('server.example.tld')
>>> resp = client.login('userid', 'secretpassword')
>>>
EPP命令和响应
通过EppClient.write 方法,EPP文档可以字符串的方式发送。或者使用EPPDoc这个子类。
>>> from eppy.doc import EppInfoDomainCommand
>>> cmd = EppInfoDomainCommand()
>>> cmd.name = "example.org"
>>> print cmd
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<domain:info xmlns="urn:ietf:params:xml:ns:domain-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<name>example.org</name>
</domain:info>
</info>
</command>
</epp>
>>> repr(cmd)
"{'epp': {'command': {'info': {'domain:info': {'name': 'example.org'}}}}}"
使用类 XmlDictObject
XmlDictObject is a convenience wrapper for generating and reading EPP documents by translating to and from Python dictionary.
>>> from eppy.xmldict import XmlDictObject
>>> o = XmlDictObject({'x': {}})
>>> print o.to_xml([])
<x />
Creating a child element with an attribute and text node:
>>> o['x'] = {'d': {'@a': 'true', '_text': '1'}}
>>> print o.to_xml({})
<x>
<d a="true">1</d>
</x>
As a shorthand for elements without attributes:
>>> o['x'] = {'d': 1}
>>> print o.to_xml({})
<x>
<d>1</d>
</x>
Multiple elements?
>>> o['x'] = {'d': ['1', '2', '3']}
>>> print o.to_xml({})
<x>
<d>1</d>
<d>2</d>
<d>3</d>
</x>