我正在尝试按照 gandi api support doc 中的描述在 gandi api 中设置 DS 记录
它声明“导入 xmlrpclib”,但我立即收到错误“找不到模块”(全文转载如下)。
我found this page他们使用“from xmlrpc import client”的地方,但在我的上下文中,gandi API 没有响应。
python3 session :
>>> import xmlrpclib
Traceback (most recent call last):
File "<pyshell#69>", line 1, in <module>
import xmlrpclib
ImportError: No module named 'xmlrpclib'
>>> from xmlrpc import client
>>> api = xmlrpclib.ServerProxy('https://rpc.gandi.net/xmlrpc/')
Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
api = xmlrpclib.ServerProxy('https://rpc.gandi.net/xmlrpc/')
NameError: name 'xmlrpclib' is not defined
>>> api = xmlclient.ServerProxy('https://rpc.gandi.net/xmlrpc/')
Traceback (most recent call last):
File "<pyshell#72>", line 1, in <module>
api = xmlclient.ServerProxy('https://rpc.gandi.net/xmlrpc/')
NameError: name 'xmlclient' is not defined
>>> api = client.ServerProxy('https://rpc.gandi.net/xmlrpc/')
>>> apikey = '<my_api_key_here>'
>>> version = api.version.info(apikey)
>>> print(version)
{'api_version': '3.3.29'}
>>> domain.dnssec.create('KEY', 'domain2.com', 1, 256, 'KEY')
Traceback (most recent call last):
File "<pyshell#77>", line 1, in <module>
domain.dnssec.create('KEY', 'domain2.com', 1, 256, 'KEY')
NameError: name 'domain' is not defined
>>> client.dnssec.create('KEY', 'domain2.com', 1, 256, 'KEY')
Traceback (most recent call last):
File "<pyshell#78>", line 1, in <module>
client.dnssec.create('KEY', 'domain2.com', 1, 256, 'KEY')
AttributeError: 'module' object has no attribute 'dnssec'
我如何通过 gandi API 更新 DS 记录?
更新: 向我提供了以下代码,并出现无效 key 错误的错误。 我使用的 key 在 PhP 中是众所周知的
my_in_file = open('/home/ex-mailer-domains/'+domain+'/dsset-'+domain+'.', 'rt')
dstext = my_in_file.read()
dslist = dstext.split()[3:7]
print(dslist[3])
api = client.ServerProxy('https://rpc.gandi.net/xmlrpc/')
apikey = 'MyKeyThatWorksInPHPjustFineForOtherScripts'
api.domain.dnssec.create(apikey, 'domain2.com', {'algorithm': 8, 'flags': 256, 'public_key': dslist[3]})
xmlrpc.client.Fault: <Fault 510150: 'Error on object : OBJECT_ACCOUNT (CAUSE_NORIGHT) [Invalid API key]'>
更新: key 适用于此示例代码
但是在其他调用中使用它,我仍然得到错误:
>>> api = client.ServerProxy('https://rpc.gandi.net/xmlrpc/')
>>> apikey = 'MyKeyThatWorksInPHPjustFineForOtherScripts'
>>> version = api.version.info(apikey)
>>> print(version)
{'api_version': '3.3.29'}
>>> domain.dnssec.create('xxxxx', 'domain2.com', 1, 256, '97BF8186C193EBF12A794A75FEF4B331A29C1A26')
请您参考如下方法:
我不确定您是否提供了真实的 API key ,但我敦促您尽快更改它。在任何情况下,在 Python 中,顶级变量/名称都不是凭空而来的——它们是由 import 或赋值语句 (x = 123) 引入的, (或者通常是 def、class 等其他语句)。
您从未将任何内容分配给domain 变量,那么它不可能工作; xmlrpclib 也是如此;由于 import 语句失败,因此未定义名称。
那么如何:
>>> from xmlrpc import client
>>> api = client.ServerProxy('https://rpc.gandi.net/xmlrpc/')
>>> apikey = '123'
>>> api.domain.dnssec.create(apikey, 'domain2.com', {'algorithm': 42,
'flags': 123, 'public_key': 'foobarbaz'})
