porkbundomains / porkbun-dynamic-dns-python

Our minimalist dynamic DNS client written in Python
MIT License
108 stars 29 forks source link

JSON Decode Error #2

Open Kuuchuu opened 3 years ago

Kuuchuu commented 3 years ago

I set the script up to run on reboot to update a bunch of domains. It worked for a few of them, but most failed. This is a snippet from my CRON log:

Subject: Cron <k****u@the-server> /bin/python3 /External/porkbun-dynamic-dns-python/porkbun-ddns.py /External/porkbun-dynamic-dns-python/config.json s*******k.cloud -i ${myip}
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/k****u>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=k****u>
Message-Id: <20210621052204.A7A2CEC0D3@the-server.T****h>
Date: Mon, 21 Jun 2021 00:22:04 -0500 (CDT)

Deleting existing A Record
Creating record: sudoz***k.cloud with answer of 67.***.***.217
Traceback (most recent call last):
  File "/External/porkbun-dynamic-dns-python/porkbun-ddns.py", line 50, in <module>
    print(createRecord()["status"])
  File "/External/porkbun-dynamic-dns-python/porkbun-ddns.py", line 28, in createRecord
    create = json.loads(requests.post(apiConfig["endpoint"] + '/dns/create/'+ rootDomain, data = json.dumps(createObj)).text)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

From k****u@the-server.T****h  Mon Jun 21 00:22:04 2021
Return-Path: <k****u@the-server.T****h>
X-Original-To: k****u
Delivered-To: k****u@the-server.T****h
Received: by the-server.T****h (Postfix, from userid 1000)
        id DBA18EC0AE; Mon, 21 Jun 2021 00:22:03 -0500 (CDT)
From: root@the-server.T****h (Cron Daemon)
To: k****u@the-server.T****h
Subject: Cron <k****u@the-server> /bin/python3 /External/porkbun-dynamic-dns-python/porkbun-ddns.py /External/porkbun-dynamic-dns-python/config.json z***k.download -i ${myip}
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/k****u>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=k****u>
Message-Id: <20210621052203.DBA18EC0AE@the-server.T****h>
Date: Mon, 21 Jun 2021 00:22:03 -0500 (CDT)

Traceback (most recent call last):
  File "/External/porkbun-dynamic-dns-python/porkbun-ddns.py", line 47, in <module>
    myIP=getMyIP() #otherwise use the detected exterior IP address
  File "/External/porkbun-dynamic-dns-python/porkbun-ddns.py", line 14, in getMyIP
    ping = json.loads(requests.post(apiConfig["endpoint"] + '/ping/', data = json.dumps(apiConfig)).text)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

From k****u@the-server.T****h  Mon Jun 21 00:22:04 2021
Return-Path: <k****u@the-server.T****h>
X-Original-To: k****u
Delivered-To: k****u@the-server.T****h
Received: by the-server.T****h (Postfix, from userid 1000)
        id B2D57EC0AE; Mon, 21 Jun 2021 00:22:04 -0500 (CDT)
From: root@the-server.T****h (Cron Daemon)
To: k****u@the-server.T****h
Subject: Cron <k****u@the-server> /bin/python3 /External/porkbun-dynamic-dns-python/porkbun-ddns.py /External/porkbun-dynamic-dns-python/config.json z***k.family www -i ${myip}
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/k****u>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=k****u>
Message-Id: <20210621052204.B2D57EC0AE@the-server.T****h>
Date: Mon, 21 Jun 2021 00:22:04 -0500 (CDT)

Deleting existing A Record
Creating record: www.z***k.family with answer of 67.***.***.217
Traceback (most recent call last):
  File "/External/porkbun-dynamic-dns-python/porkbun-ddns.py", line 50, in <module>
    print(createRecord()["status"])
  File "/External/porkbun-dynamic-dns-python/porkbun-ddns.py", line 28, in createRecord
    create = json.loads(requests.post(apiConfig["endpoint"] + '/dns/create/'+ rootDomain, data = json.dumps(createObj)).text)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

From k****u@the-server.T****h  Mon Jun 21 00:22:04 2021
Return-Path: <k****u@the-server.T****h>
X-Original-To: k****u
Delivered-To: k****u@the-server.T****h
Received: by the-server.T****h (Postfix, from userid 1000)
        id B8883EC0AE; Mon, 21 Jun 2021 00:22:04 -0500 (CDT)
From: root@the-server.T****h (Cron Daemon)
To: k****u@the-server.T****h
Subject: Cron <k****u@the-server> myip="$(dig +short myip.opendns.com @resolver1.opendns.com)" && /bin/python3 /External/porkbun-dynamic-dns-python/porkbun-ddns.py /External/porkbun-dynamic-dns-python/config.json z***k.io -i ${myip}
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/k****u>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=k****u>
Message-Id: <20210621052204.B8883EC0AE@the-server.T****h>
Date: Mon, 21 Jun 2021 00:22:04 -0500 (CDT)

Deleting existing A Record
Creating record: z***k.io with answer of 67.***.***.217
SUCCESS

Thanks for making this, really appreciate it!

rossporkbun commented 3 years ago

Hmm, I'm wondering if the API is throttling you due to doing a bunch of transactions in a row. I'll see if I can recreate and/or at least do some better error handling in here to make it more apparent what the issue is. This is one of my first Python projects, so I'm still getting used to doing proper error handling. Thanks for the thorough report.