服务与支持

首页 > 服务与支持 > 帮助中心 > API

CloudXNS API Python SDK

CloudXNS技术支持 2015-11-06

这是一款智能DNS CloudXNS 官方推出一个CloudXNS系统API的 Python SDK包,使用比较方便,完整的支持了所有API操作。

Install

Install First

Extract the archive file downloaded from CloudXNS-API-SDK-Python.zip to your project. You can install Package:

pip install restclient
python setup.py install

Install Second

you can then install using the following command:

pip install CloudXNS-API-SDK-Python

Demo

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from cloudxns.api import *
try:
    import json
except ImportError:
    import simplejson as json

if __name__ == '__main__':

    print 'CloudXNS API Version: ', Api.vsersion()
    api_key = 'XXXXXX'
    secret_key = 'XXXXXX'
    api = Api(api_key=api_key, secret_key=secret_key)
    # api.set_debug(True)

    """
    功能 域名列表
    HTTP 请求方式 GET
    URL https://www.cloudxns.net/api2/domain
    :return: String
    """
    result = api.domain_list()
    print result['message']
    print result['data']

    """
    功能 添加域名
    HTTP 请求方式 POST
    URL https://www.cloudxns.net/api2/domain
    :return: String
    """
    import random
    domain = "sdk-test%d.com" % random.randint(1000, 100000)
    result = api.domain_add(domain)
    print result

    """
    功能 删除域名
    HTTP 请求方式 DELETE
    URL https://www.cloudxns.net/api2/domain
    :return: String
    """
    result = api.domain_delete(32224)
    print result

    """
        功能  DDNS快速修改解析记录值
        HTTP请求方式    POST
        URL https://www.cloudxns.net/api2/ddns
        domain:(必选)已存在的完整域名(如主机记录为@时domain是cloudxns.net,为www时domain是www.cloudxns.net)
        ip:(可选)记录IP值(8.8.8.8)或者多个IP值中间用|分割(8.8.8.8|1.1.1.1);为空时IP值由API自动获取客户端IP
        line_id:(可选)线路id(通过API获取),默认值1(全网默认)
    """
    result = api.ddns('ddns.a.com')
    print result

下载CloudXNS API Python SDK请点此处

10 个回复

祥子 2016-12-13

@tyqq
官方已fork

灰姑娘 2016-09-30

感谢 @tyqq 的热心提供…… 很赞!

tyqq 2016-09-30

CloudXNS 官方提供的SDK是基于Pyton2提供的,本项目根据CloudXNS官方提供的API开发了Python3上可以正常使用的SDK。
github项目地址
>https://github.com/wevsty/CloudXNS_Python3_SDK

如有问题也可以在论坛反馈,帖子地址
>https://www.cloudxns.net/Support/detail/id/2233.html


CloudXNS官方api文档,返回的错误代码请参考
>https://www.cloudxns.net/Public/Doc/CloudXNS_api2.0_doc_zh-cn.zip

本项目集成了CloudXNS的HTTP DNS功能,关于HTTP DNS功能请参考
>https://www.cloudxns.net/Index/HttpDNS.html
如发现本SDK存在问题,请联系我进行改进。

Examples
--------
使用之前请先import CloudXNS_APISDK

import CloudXNS_APISDK
#设置API KEY
api=CloudXNS_API(api_key='fffffffffffffffffffffffffffffffff',secret_key='ffffffffffffffff',debug_log=True)
#返回域名列表 返回内容为json格式str
print(api.domain_list())
#向账户添加域名 test.org
api.domain_add('test.org')
#快速修改ddns记录的值
api.domain_host_DDNS('ddns.test.org')
#http dns请求www.test.net
str=api.http_dns_get('www.test.net')
#转换str到dict
dict=api.json_strtodict(str)

***更多功能,使用说明请参考官方文档或SDK中的注释***

tinnny 2016-08-18

版本号不应该是version么?vsersion是什么鬼。。。

祥子 2016-08-01

@寒山寺
明显的你的域名请求错了,正确的域名是www.cloudxns.net

寒山寺 2016-06-26

Traceback (most recent call last):
File "./watcher.py", line 8, in <module>
did, hid, rid, ip = common.login()
File "/home/wxn/Work/IPReport/common.py", line 12, in login
response = api.domain_list()
File "/home/wxn/anaconda2/lib/python2.7/site-packages/cloudxns/api.py", line 92, in domain_list
return self.__request('GET', 'domain')
File "/home/wxn/anaconda2/lib/python2.7/site-packages/cloudxns/api.py", line 77, in __request
params=data, headers=self.__headers, resp=self.__debug, async=False)
File "/home/wxn/anaconda2/lib/python2.7/site-packages/restclient/__init__.py", line 190, in GET
httplib_params=httplib_params)
File "/home/wxn/anaconda2/lib/python2.7/site-packages/restclient/__init__.py", line 335, in rest_invoke
resp, httpcallback, credentials, httplib_params)
File "/home/wxn/anaconda2/lib/python2.7/site-packages/restclient/__init__.py", line 402, in _rest_invoke
httplib_params=httplib_params)
File "/home/wxn/anaconda2/lib/python2.7/site-packages/restclient/__init__.py", line 434, in non_multipart
params.encode('utf-8'), headers)
File "/home/wxn/anaconda2/lib/python2.7/site-packages/httplib2/__init__.py", line 1609, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/home/wxn/anaconda2/lib/python2.7/site-packages/httplib2/__init__.py", line 1351, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/home/wxn/anaconda2/lib/python2.7/site-packages/httplib2/__init__.py", line 1272, in _conn_request
conn.connect()
File "/home/wxn/anaconda2/lib/python2.7/site-packages/httplib2/__init__.py", line 1047, in connect
'host %s: %s' % (hostname, cert), hostname, cert)
httplib2.CertificateHostnameMismatch: Server presented certificate that does not match host www.cloudxns.net: {'crlDistributionPoints': (u'http://crls2.wosign.cn/ca2g2-server1-free.crl';,), 'subjectAltName': (('DNS', 'cloudxns.newdefend.com'),), 'notBefore': u'Dec 2 08:10:33 2015 GMT', 'caIssuers': (u'http://aia2.wosign.cn/ca2g2.server1.free.cer';,), 'OCSP': (u'http://ocsp2.wosign.cn/ca2g2/server1/free';,), 'serialNumber': u'125222ACE4AAEA409E938B96C70003C6', 'notAfter': 'Dec 2 08:10:33 2016 GMT', 'version': 3L, 'subject': ((('commonName', u'cloudxns.newdefend.com'),),), 'issuer': ((('countryName', u'CN'),), (('organizationName', u'WoSign CA Limited'),), (('commonName', u'CA \u6c83\u901a\u514d\u8d39SSL\u8bc1\u4e66 G2'),))}

怎么有 SSL 错误呀?

xuboying 2016-02-14

pip 里的模块没有跟新啊啊啊啊啊

祥子 2015-12-23

@图腾泰科 Python API已更新解决了你的这个问题。
SSL3_GET_SERVER_CERTIFICATE:certificate verify failed ,这是httplib2 SSL证书验证出错,加了一个'disable_ssl_certificate_validation':True的参数就好了

图腾泰科 2015-12-17

httplib2.SSLHandshakeError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

碰到这个问题,怎么办

环境: CentOS7.1 Python2.7

p0we7 2015-11-09

淘宝这个IP获取 ,我都不想吐槽了。

10次有8次获取失败呵呵

请先后回复

我想说

全部热门标签

全部 热门问题

返回顶部
微信

微信扫描二维码,关注CloudXNS公众号

>
QQ
新浪微博