observerss / pygodaddy

3rd Party Client Library for Manipulating Go Daddy DNS Records.
https://pygodaddy.readthedocs.org/
Other
37 stars 30 forks source link

pygodaddy no longer updates dns A records. #7

Closed artoleus closed 9 years ago

artoleus commented 9 years ago

This has been working fine until recently (6th March I think). I made no changes but pygodaddy no longer updates the A records on Goddaddy for my .net .com or .co.uk sites. It says in the log that it is updating but if I do it manually in the python console the return from client.update_dns_record() is "false".

update: I have downgraded to pygodaddy 0.1.7. and the updating of the .net and .com domains appears to work with this version so the problem is directly related to the recent update 0.1.8. to fix domains with multi-dotted TLDs

ghost commented 9 years ago

I can't seem to reproduce a parsing error that differs between versions 0.1.7 and 0.1.8. Are you using the FQDN when calling client.update_dns_record() i.e. www.example.com rather than example.com?

artoleus commented 9 years ago

I am using the find domains function to pass the domains to update_dns_record.

Having thought about it some more I would think the culprit is the _split_hostname function. I have now typed this out manually in a python console to see what various outputs you get with varius combinations of hostnames. The previous try: except combination relied on rsplit producing an exception if the number of '.' was <>2. In this case the 'domain = hostname' and the prefix=@ was used which works for those 'www.example.com' or 'example.com' but not the .co.uk, however in the case of using partition the except is never called as it does not produce an error.

I think the resolution would be to revert to rsplit to be able to call the exception then add an if else in the exception to handle the www.example.co.uk domains. ..or something like that anyway :-)

Update: So to demonstrate why the 0.1.8 is not working for me I tested it with this manual python code

from pygodaddy import GoDaddyClient client = GoDaddyClient() GODADDY_USERNAME="######" GODADDY_PASSWORD="######" client.login(GODADDY_USERNAME, GODADDY_PASSWORD) True for domain in client.find_domains(): ... print domain ... example.co.uk example.com example.net for domain in client.find_domains(): ... prefix, domain3 = client._split_hostname(domain) ... print domain3 ... print prefix ... print domain ... co.uk example example.co.uk com. example example.com net. example example.net

And this is the code for 0.1.7. from pygodaddy import GoDaddyClient client = GoDaddyClient() GODADDY_USERNAME="#######" GODADDY_PASSWORD="#######" client.login(GODADDY_USERNAME, GODADDY_PASSWORD) True for domain in client.find_domains(): ... print domain ... example.co.uk example.com example.net for domain in client.find_domains(): ... prefix, domain3 = client._split_hostname(domain) ... print domain3 ... print prefix ... print domain ... co.uk example example.co.uk example.com @ example.com example.net @ example.net

ghost commented 9 years ago

Ahh, I see. Thanks for the reply. I'll get to work on this!

ghost commented 9 years ago

There doesn't seem to be a clean way of doing this that will cover all bases. Perhaps we should revert back to 0.1.7 so that it isn't broken for most people.

Any ideas of how to implement this without literally providing a list of TLDs to compare against?

@observerss @artoleus

observerss commented 9 years ago

may be we should use a whitelist of domain postfixs to recognize this or we need to find a cleverer way for now, just use 0.1.7

artoleus commented 9 years ago

Sorry I'm inexperienced with python and github so still not confident about forking.

Here is what I have so far:

import tldextract def _split_hostname(_self,hostname): extracted = tldextract.extract(hostname) prefix = extracted.subdomain domain = extracted.domain+'.'+extracted.suffix return prefix, domain

ghost commented 9 years ago

Nice find with tldextract. I've stuck it in the code and it now looks like this:

def _split_hostname(self, hostname):
    """ split hostname into prefix + domain """
    ext = tldextract.extract(hostname)
    prefix = ext.subdomain
    domain = ext.registered_domain 
    if not prefix:
        prefix = '@'
    return prefix, domain

Running tests on it produces the desired results, I believe:

http://www.test.co.uk => www, test.co.uk
       www.test.co.uk => www, test.co.uk
           test.co.uk =>   @, test.co.uk
  http://www.test.com => www, test.com
         www.test.com => www, test.com
             test.com =>   @, test.com

Do you want me to do the fork/pull request, or would you like to give it a go?

artoleus commented 9 years ago

please go ahead. I'll practice some first.