Jeromba6
Jeromba6

Reputation: 433

I can't get python module for transip to work correctly

I try to get a script to work for checking / editing my dns at transip. It works partly until I realy want to do something.

Current code:

#!/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))

The result when running is al follows:

./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'

What am I doing wrong? The first 2 commands seem to work but the dnsservice.get_info(basedomain) isn't working

Version of transip module

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: [email protected]
License: MIT
Location: /usr/local/lib/python3.7/dist-packages
Requires: cryptography, suds-jurko, requests
Required-by: 

Upvotes: 2

Views: 157

Answers (1)

kimbo
kimbo

Reputation: 2693

Just so you know, I don't know much about the transip api.

I took a look at their code where the error is being thrown in transip/service/objects.py, and it looks like they have a bug:

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

The comment says that other can be a list so they're ensuring that it's a DNSEntry, but they're actually not checking that at all. If self has the attributes name, type, and content, and other does not, this will break. In your case, other is a list so it doesn't have the name attribute.

Something like changing the first if statement to check other instead of self may solve it:

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

It would actually probably be better to just check if other is a list:

if isinstance(other, list):
   return False

If I were you, I'd either open an issue in transip API GitHub repo, or do a quick fix yourself and submit a pull request.

Upvotes: 1

Related Questions