【问题标题】:I can't get python module for transip to work correctly我无法让 python 模块让 transip 正常工作
【发布时间】:2020-03-01 21:43:59
【问题描述】:

我尝试让一个脚本在 transip 中检查/编辑我的 dns。在我真正想做某事之前,它会部分起作用。

当前代码:

#!/usr/bin/env python3

from transip.service.domain import DomainService

basedomain='gemert.net'
key='MY_KEY_IS_SECRET'

dnsservice = DomainService('MY_USERNAME', private_key=key)
print(dnsservice.get_domain_names())
print(dnsservice.check_availability(basedomain))
print(dnsservice.get_info(basedomain))

运行时的结果如下:

./setdns.py 
[mydomain1.com, mydomain2.org, mydomain3.net]
inyouraccount
Traceback (most recent call last):
  File "./setdns.py", line 49, in <module>
    print(dnsservice.get_info(basedomain))
  File "/usr/local/lib/python3.7/dist-packages/suds/__init__.py", line 166, in <lambda>
    __str__ = lambda x: x.__unicode__()
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 172, in __unicode__
    return self.__printer__.tostr(self)
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 256, in tostr
    return self.process(object, history, indent)
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 265, in process
    return self.print_object(object, h, n+2, nl)
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 312, in print_object
    s.append(self.process(item[1], h, n, True))
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 273, in process
    return self.print_collection(object, h, n+2)
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 352, in print_collection
    s.append(self.process(item, h, n-2))
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 265, in process
    return self.print_object(object, h, n+2, nl)
  File "/usr/local/lib/python3.7/dist-packages/suds/sudsobject.py", line 282, in print_object
    if d in h:
  File "/usr/local/lib/python3.7/dist-packages/transip/service/objects.py", line 57, in __eq__
    return self.name == other.name and self.type == other.type and self.content == other.content
AttributeError: 'list' object has no attribute 'name'

我做错了什么?前 2 个命令似乎有效,但 dnsservice.get_info(basedomain) 无效

transip 模块的版本

pip3 show transip
Name: transip
Version: 2.0.0
Summary: TransIP API Connector
Home-page: https://github.com/benkonrath/transip-api
Author: Go About B.V.
Author-email: tech@goabout.com
License: MIT
Location: /usr/local/lib/python3.7/dist-packages
Requires: cryptography, suds-jurko, requests
Required-by: 

【问题讨论】:

    标签: python api dns


    【解决方案1】:

    请注意,我对 transip api 了解不多。

    我查看了他们在transip/service/objects.py 中抛出错误的代码,看起来他们有一个错误:

    def __eq__(self, other): 
        # other can be a list. This check ensures that other is a DnsEntry. 
        if not hasattr(self, 'name') or not hasattr(self, 'type') or not hasattr(self, 'content'): 
            return False 
    
        # expire is intentionally not used for equality. 
        return self.name == other.name and self.type == other.type and self.content == other.content
    
    

    评论说other 可以是一个列表,因此他们确保它是一个 DNSEntry,但实际上他们根本没有检查它。如果self 具有属性nametypecontent,而other 没有,这将中断。在您的情况下,other 是一个列表,因此它没有 name 属性。

    将第一个 if 语句更改为检查 other 而不是 self 可能会解决它:

    if not hasattr(other, 'name') or not hasattr(other, 'type') or not hasattr(other, 'content'): 
            return False 
    

    实际上最好只检查other 是否是一个列表:

    if isinstance(other, list):
       return False
    

    如果我是你,我会在 transip API GitHub 存储库中打开一个问题,或者自己快速修复并提交拉取请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 2020-12-10
      • 2012-09-05
      • 2017-11-06
      • 2011-09-06
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多