Giter VIP home page Giter VIP logo

godaddypy's Introduction

downloads climate

GoDaddyPy

Python library useful for updating DNS settings through the GoDaddy v1 API.

Setup

First, go to https://developer.godaddy.com/keys/ and request a production API key and secret.

Note: Sometimes the production API keys don't seem to work correctly. Just delete it and request another one.

Second, install GoDaddyPy with pip.

$ pip install godaddypy

GoDaddyPy supports three methods for providing your credentials to the library, which are honored in the following order:

  1. Passing them directly to the Account object
  2. Setting the GODADDY_API_KEY and GODADDY_API_SECRET environment variables
  3. Storing them in a credentials.yml file

For convenience, a configuration tool has been provided that can be run from your terminal or in Python. This tool will prompt for your API key and secret, and store them in a config file in your home directory following the XDG Base Directory specification. I have only tested this on Mac, but it should also work on Linux. I recommend env vars for Windows and/or CI/CD.

$ python -m godaddypy
>>> from godaddypy import Account
>>> acct = Account.configure()
Enter GoDaddy API Key [None]: example_key
Enter GoDaddy API Secret [None]: example_secret
>>> account = Account()
>>> account._config
Configuration(key='example_key', secret='example_secret')

Examples

Also see /examples for more examples.

>>> from godaddypy import Client, Account
>>>
>>> my_acct = Account(api_key='PUBLIC_KEY', api_secret='SECRET_KEY')
>>> client = Client(my_acct)
>>>
>>> # Or if you want to use a delegate...
>>> delegate_acct = Account(api_key='PUBLIC_KEY', api_secret='SECRET_KEY', delegate='DELEGATE_ID')
>>> delegate_client = Client(delegate_acct)
>>>
>>> client.get_domains()
['domain1.example', 'domain2.example']
>>>
>>> client.get_records('domain1.example', record_type='A')
[{'name': 'dynamic', 'ttl': 3600, 'data': '1.1.1.1', 'type': 'A'}]
>>>
>>> client.update_ip('2.2.2.2', domains=['domain1.example'])
True
>>>
>>> client.get_records('domain1.example')
[{'name': 'dynamic', 'ttl': 3600, 'data': '2.2.2.2', 'type': 'A'}, {'name': 'dynamic', 'ttl': 3600, 'data': '::1',
'type': 'AAAA'},]
>>>
>>> client.get_records('apple.com', record_type='A', name='@')
[{u'data': u'1.2.3.4', u'type': u'A', u'name': u'@', u'ttl': 3600}]
>>>
>>> client.update_record_ip('3.3.3.3', 'domain1.example', 'dynamic', 'A')
True
>>>
>>> client.add_record('apple.com', {'data':'1.2.3.4','name':'test','ttl':3600, 'type':'A'})
True
>>>
>>> client.delete_records('apple.com', name='test')
True

Contributing

If you want to contribute, first off: thank you! Second, please check out the Contributing Guidelines, CONTRIBUTING.

Steps to Contribute

  1. Pull the repository
  2. Run make install to install the library and development dependencies
  3. Make changes
  4. Add tests
  5. Open a pull request towards the main branch

godaddypy's People

Contributors

andreasloow avatar ashkulz avatar bahadir avatar bverschueren avatar dependabot-preview[bot] avatar dependabot[bot] avatar examadeus avatar examadeus-zz avatar getsurreal avatar jlegido avatar josteink avatar jremes-foss avatar juyeh avatar pack3tl0ss avatar phoerious avatar sethc23 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

godaddypy's Issues

[BUG] Copy pasta?

I notice here that it seems that one should be GODADDY_API_KEY and one should be GODADDY_API_SECRET - is this copy pasta?

I actually have not used the package yet, I'm still surveying my options and as a part of that was glancing through the source. I can't tell you how this is or is not an actual bug or how it would manifest

Hope this is helpful, sorry if it's just spam :)

(

key = prompter.get_value(getattr(config, "key", None), "GODADDY_API_KEY", "Enter GoDaddy API Key")
secret = prompter.get_value(getattr(config, "secret", None), "GODADDY_API_KEY", "Enter GoDaddy API Secret")
)

godaddy API Change?

Response Data: {
u'fields': [ {
u'path': u'records',
u'message': u'is not a array',
u'code': u'UNEXPECTED_TYPE'
} ],
u'message': u"Request body doesn't fulfill schema, see details in fields",
u'code': u'INVALID_BODY'
}

[BUG] Missing dependencies

Describe the bug
Your requirements are not correctly documented, causing them to not be installed, resulting in a broken package. The install_requires parameter in your setup.py needs to include everything in your requirements.txt.

To Reproduce
Steps to reproduce the behavior:

python3.11 -m venv .env
. .env/bin/activate
pip install GoDaddyPy==2.5.1
python -c "from godaddypy import Client, Account"

Expected behavior
Package should be importable after installation. Instead, package throws the error: ModuleNotFoundError: No module named 'configloader'

how to use godaddypy with proxy

Describe the bug
Failed to establish a new connection: [WinError 10051] 向一个无法连接的网络尝试了一个套接字操作。'))

In the Chinese network, I must use a proxy to access godaddy . how can i use godaddypy with proxy

requests.exceptions.SSLError: HTTPSConnectionPool(host='api.godaddy.com', port=443): Max retries exceeded with url

We are using godaddypy lib to manage our godaddy records.
We are running api's multiple times as part of our CI\CD pipeline and we got following error on one of instance, can you please help us analyze and fix same.

I have gone through multiple forums and found one issue logged with requests lib for similar error.
psf/requests#4256
But since we are not directly invoking requests , I am not sure how to tackle this.
We are invoking this API's from Docker container running inside Ubuntu Host
Versions used.
GoDaddyPy==2.2.5
requests==2.18.4

get_record("A",recordname,domainname)

return self.godaddy_client.get_records(domainname, recordtype, name=recordname)
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/godaddypy/client.py", line 180, in get_records
[20:40:08] data = self._get_json_from_response(url)
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/godaddypy/client.py", line 56, in _get_json_from_response
[20:40:08] return self._request_submit(requests.get, url=url, json=json, **kwargs).json()
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/godaddypy/client.py", line 80, in _request_submit
[20:40:08] resp = func(headers=self._get_headers(), **kwargs)
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 72, in get
[20:40:08] return request('get', url, params=params, **kwargs)
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 58, in request
[20:40:08] return session.request(method=method, url=url, **kwargs)
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 508, in request
[20:40:08] resp = self.send(prep, **send_kwargs)
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 618, in send
[20:40:08] r = adapter.send(request, **kwargs)
[20:40:08] File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 506, in send
[20:40:08] raise SSLError(e, request=request)
[20:40:08]requests.exceptions.SSLError: HTTPSConnectionPool(host='api.godaddy.com', port=443): Max retries exceeded with url: /v1/domains//records/A/ (Caused by SSLError(SSLError("bad handshake: SysCallError(104, 'ECONNRESET')",),))

Bug in `update_ip` for Python 3

In function update_ip of client.py, the following check does not work for python 3:

if (
    subdomains is None or
    (isinstance(subdomains, (unicode, str)) and r_name == subdomains) or
     r_name in subdomains
):

This seems a bug as the rest of the function is careful in specifying behaviours for both python 2 and python 3. That is easy to fix, the check could simply become as follows for python 3:

if (
    subdomains is None or
    (isinstance(subdomains, str) and r_name == subdomains) or
     r_name in subdomains
):

requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity

I'm able to connect to the server, but when I call "client.update_ip" I get the following error:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/godaddypy/client.py", line 96, in _validate_response_success
response.raise_for_status()
File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://api.godaddy.com/v1/domains/casahespanha.com/records/A/@

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./godaddypy-dyndns.py", line 48, in
rc=client.update_ip(public_ip, domains=[domain])
File "/usr/local/lib/python3.5/dist-packages/godaddypy/client.py", line 245, in update_ip
self.update_record(domain, record)
File "/usr/local/lib/python3.5/dist-packages/godaddypy/client.py", line 299, in update_record
self._put(url, json=record)
File "/usr/local/lib/python3.5/dist-packages/godaddypy/client.py", line 66, in _put
return self._request_submit(requests.put, url=url, json=json, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/godaddypy/client.py", line 82, in _request_submit
self._validate_response_success(resp)
File "/usr/local/lib/python3.5/dist-packages/godaddypy/client.py", line 98, in _validate_response_success
raise BadResponse(response.json())
godaddypy.client.BadResponse: Response Data: {'fields': [{'path': 'records', 'message': 'is not a array', 'code': 'UNEXPECTED_TYPE'}], 'message': "Request body doesn't fulfill schema, see details in fields", 'code': 'INVALID_BODY'}

This happens even with the code in the README.rst example

Any idea what the problem could be?

how can i get all domains

how can i get all domains, i used client.get_domains() to get all doamins, but i get a little only. i find the limit args in official docmetion, but i do not know how to use... help me. think you

not getting all domains

We are getting the response as combination of reseller account and self account available domain names and also all the available domain names are not listed.

problem with deleting records (with the record_type option)

Hi,
I've been trying to delete MX records using this code line:

client.delete_records(domain, name='@', record_type='MX')

The long error message ends wtih:
godaddypy.client.BadResponse: Response Data: {'code': 'INVALID_RECORDS', 'fields': [{'code': 'INVALID_RECORDS', 'message': 'Invalid [ipaddress] provided for record data, [Parked].', 'path': 'records'}], 'message': 'One or more of the given records is invalid', 'errors': ['Invalid [ipaddress] provided for record data, [Parked].']}

I can't really see what I'm doing wrong, the code line is simple enough and all I did is to add the record_type='MX' which should work according to the documentation.

ALSO, I this line DOES work:
mx_records = client.get_records(domain, record_type='MX')
(which means that there's nothing wrong with "record_type='MX'")

Auth not working

Thanks for your work on this - I'm hoping to do some things that godaddy tech support can't help me with.

Following your sample code with my apikey/secret raised an exception:

In [1]: from godaddypy import Client, Account

In [2]: my_acct = Account(api_key='...', api_secret='...')

In [3]: client = Client(my_acct)                                                                                             

In [4]: client.get_domains()                                                                                                 
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~/anaconda/lib/python3.8/site-packages/godaddypy/client.py in _validate_response_success(response)
    104         try:
--> 105             response.raise_for_status()
    106         except Exception:

~/anaconda/lib/python3.8/site-packages/requests/models.py in raise_for_status(self)
    942         if http_error_msg:
--> 943             raise HTTPError(http_error_msg, response=self)
    944 

HTTPError: 401 Client Error: Unauthorized for url: https://api.godaddy.com/v1/domains

During handling of the above exception, another exception occurred:

BadResponse                               Traceback (most recent call last)
<ipython-input-4-fe3d6858cad8> in <module>
----> 1 client.get_domains()

~/anaconda/lib/python3.8/site-packages/godaddypy/client.py in get_domains(self, **params)
    147         """
    148         url = self.API_TEMPLATE + self.DOMAINS
--> 149         data = self._get_json_from_response(url, params=params)
    150         domains = list()
    151         for item in data:

~/anaconda/lib/python3.8/site-packages/godaddypy/client.py in _get_json_from_response(self, url, json, **kwargs)
     73 
     74     def _get_json_from_response(self, url, json=None, **kwargs):
---> 75         return self._request_submit(requests.get, url=url, json=json, **kwargs).json()
     76 
     77     def _log_response_from_method(self, req_type, resp):

~/anaconda/lib/python3.8/site-packages/godaddypy/client.py in _request_submit(self, func, **kwargs)
     95         resp = func(headers=self._get_headers(), **kwargs)
     96         self._log_response_from_method(func.__name__, resp)
---> 97         self._validate_response_success(resp)
     98         return resp
     99 

~/anaconda/lib/python3.8/site-packages/godaddypy/client.py in _validate_response_success(response)
    105             response.raise_for_status()
    106         except Exception:
--> 107             raise BadResponse(response.json())
    108 
    109     def add_record(self, domain, record):

BadResponse: Response Data: {'code': 'UNABLE_TO_AUTHENTICATE', 'message': 'Unauthorized : Could not authenticate API key/secret'}

[BUG] runs abnormally

version 2.5.1
from godaddypy import Account
Traceback (most recent call last):
File "", line 1, in
File "/Users/user/lib/python3.7/site-packages/godaddypy/init.py", line 1, in
from .client import Client
File "/Users/user/lib/python3.7/site-packages/godaddypy/client.py", line 8, in
from .account import Account
File "/Users/user/lib/python3.7/site-packages/godaddypy/account.py", line 50, in
class Account(object):
File "/Users/user/lib/python3.7/site-packages/godaddypy/account.py", line 103, in Account
def __parse_configuration(self) -> Configuration | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Code runs abnormally

Suggestion for helper function.

This is a great library. Thanks!

I wrote this function which i find useful, thought others might too:
if you are doing a lot of additions/updates it is better to generate exist first and pass it in rather than have each call get the existing records.

def add_or_update(domain, ip, value, record_type='A', exist=None):

    if not exist:
        exist = client.get_records(domain, record_type=record_type)
    names = [x['name'] for x in exist]
    if value in names:
        if exist[names.index(value)]['data'] != ip:
            client.update_record_ip(ip, domain,value,record_type)
            print(f'Updated {value}.{domain} to point to {ip}.')

        else:
            print(f'{value}.{domain} already points to {ip}. Not changing anything.')
    else:
        client.add_record(domain,
              {
                  'data': ip,
                  'name': value,
                  'ttl':3600,
                  'type':record_type
               })
        print(f'Added record for {value}.{domain} to point to {ip}.')

Logger without handlers

When a log level is passed to the client (e.g. logging.DEBUG) the handler is not found raising:

No handlers could be found for logger "GoDaddyPy.Client"

Fixing it in Client.py module

   # Logging setup
        logging.basicConfig()
        self.logger = logging.getLogger('GoDaddyPy.Client')

Version 3.0.0 Milestone Planning

This is the 3.0.0 milestone planning tracker. If anyone has suggestions for things to be added/modified for the 3.0.0 release, please post them here and I'll add them to the tracker.

Upgrade API Support

Upgrade GoDaddyPy to support more than just the Domains API.

Other GoDaddy APIs currently available are:

  • Abuse
  • Aftermarket
  • Agreements
  • Certificates
  • Countries
  • Orders
  • Shoppers
  • Subscriptions

API Change? recordReplace now expects an array

https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplace

DEBUG:Response data: b'{"code":"INVALID_BODY","fields":[{"code":"UNEXPECTED_TYPE","message":"is not a array","path":"records"}],"message":"Request body doesn't fulfill schema, see details in fields"}\n'

def _put(self, url, json=None, **kwargs):
return self._request_submit(requests.put, url=url, json=json, **kwargs)

The json parameter is a dict, a quick test is to change json=[json] which passes the API.

Add tox test suite to godaddypy

Currently, the unit tests only get run against multiple versions of python through travis CI. It would be nice to have a local configuration (something like tox) that would run tests against a battery of different python versions so that developers can see if a test will fail in a certain version before having to push the commit and have CI catch the error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.