python调用dnspod API的脚本

首先,感触一下:dnspod的api文档真心写的不错,大大简化了编写脚本的难度。

代码如下:

#!/usr/bin/env python

from socket import timeout
import httplib
import urllib
import json

timeout = 5
api_url = 'dnsapi.cn'
params={}
params['login_email'] = 'xx@126.com'
params['login_password'] = 'password'
params['format'] = 'json'
params['lang'] = 'en'
params['error_on_empty'] = 'yes'
headers = {"Content-type": "application/x-www-form-urlencoded",
           "Accept": "text/plain"}

con = httplib.HTTPSConnection(api_url)
con.request('POST', '/User.Info', body=urllib.urlencode(params),
            headers=headers)
response = con.getresponse()
data = json.loads(response.read())
print data