2013-02-17 42 views
2

我想用我的IP使用python脚本更新我的rackspace dns。使用python获得我的IP

我的脚本在我手动输入IP的时候工作,但是当我从外面拿到它时不知道为什么?

WORKS:

#!/usr/bin/env python 
import clouddns 
import requests 
r= requests.get(r'http://curlmyip.com/') 
ip= '4.4.4.4' 
dns = clouddns.connection.Connection('******','********************') 

domain = dns.get_domain(name='reazem.net') 
record = domain.get_record(name='ssh.reazem.net') 
record.update(data=ip, ttl=600) 

并不:

#!/usr/bin/env python 
import clouddns 
import requests 
r= requests.get(r'http://curlmyip.com/') 
**ip= '{}'.format(r.text)** 
dns = clouddns.connection.Connection('******','********************') 

domain = dns.get_domain(name='reazem.net') 
record = domain.get_record(name='ssh.reazem.net') 
record.update(data=ip, ttl=600) 

注:print '{}'.format(r.text)成功地输出我的IP。

帮你帮我:我刚刚注意到print '{}'.format(r.text)增加了一个额外的行,我该如何避免?

对于那些有兴趣:https://github.com/rackspace/python-clouddns

回答

2

尝试ip = r.text.strip()删除多余的换行符。