benkonrath / transip-api

Python implementation for the TransIP API
https://transip-api.readthedocs.io/en/latest/
MIT License
23 stars 23 forks source link

Can't register a new domain #50

Closed wub1990 closed 2 years ago

wub1990 commented 5 years ago

Hey, I try to register a new domain but i can't get it to work.

domain_service = DomainService(login="login", private_key=api_key_file)

def register_domain(self, domain):
    domain = Domain(domain)
    result = domain_service.register(domain)
    return result

I get the next error:

suds.WebFault: Server raised fault: 'Exception received from JSON Server: Invalid API signature, signature does not match the request. (timestamp: 0.88420200 1571509529)'
roaldnefs commented 5 years ago

It looks like you are using a private key file, which requires to be set using the private_key_file parameter, e.g.:

from transip.service.vps import DomainService

PRIVATE_KEY = '''
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
'''

# You can specify the private key directly or supply the path to the private
# key file. The private_key_file will default to `decrypted_key`.
client = DomainService('accountname', private_key_file='/path/to/decrypted_key')
client = DomainService('accountname', private_key=PRIVATE_KEY)
wub1990 commented 5 years ago

This is what i have now ps. I can't seem to get the code block to work sorry for that

def __init__(self):
    self.api_key = 
    """
    -----BEGIN PRIVATE KEY-----
    # 
    -----END PRIVATE KEY-----
    """
    self.domain_service = DomainService(login="login", private_key=self.api_key)
roaldnefs commented 5 years ago

Do you get the same (Invalid API signature) error as before?

I've updated your code block by placing them between three consecutive backticks.

wub1990 commented 5 years ago

Yes that's correct. I still get that error.

Thanks for correcting the code

roaldnefs commented 5 years ago

I'm not sure what is going wrong... Would you be able to check the following questions?

Is the register_domain() part of a class? If so, could you show how the domain service is initialized and an example of a calling the register_domain() function? Don't forget the mask any personal information!

If you are certain that everything on your side is fine, then we might need to dive in the changes introduced by https://github.com/transip/transip-api-php/releases.

Unfortunately I can't test it easily for you either, because I use TransIP a lot less nowadays and there is still no test API.

wub1990 commented 5 years ago

My ip is whitelisted and the domain is in the correct format also my credeatials are correct because the rest of the code works except the register This is all of my code:

from transip.service.objects import DnsEntry, Domain
from transip.service.domain import DomainService
from suds import WebFault

class TransipApi:
    def __init__(self):
        self.api_key = """-----BEGIN PRIVATE KEY-----
key
-----END PRIVATE KEY-----"""
        self.domain_service = DomainService(login="login_name", private_key=self.api_key)

    def check_availibity(self, domain):
        result = self.domain_service.check_availability(domain)
        return result

    def get_owned_domains(self):
        domains = self.domain_service.get_domain_names()
        return domains

    def get_dns_for_domain(self, domain):
        dns_entries = self.domain_service.get_info(domain).dnsEntries
        return dns_entries

    def add_dns_record(self, domain, name, expire, record_type, content):
        dns_entries = self.domain_service.get_info(domain).dnsEntries
        dns_entries.append(DnsEntry(name=name, expire=int(expire), record_type=record_type, content=content))
        try:
            result = self.domain_service.set_dns_entries(domain, dns_entries)
        except WebFault as err:
            return err
        if result is None:
            return "ok"
        else:
            return result

    def register_domain(self, domain):
        domain = Domain(domain)
        result = self.domain_service.register(domain)
        return result

And i call it:

TransipApi().register_domain("testdomain.nl")