Skip to content

Commit

Permalink
Merge pull request #38 from qip/cf-fix2
Browse files Browse the repository at this point in the history
Fix applying parameters to Cloudflare API on GET/DELETE requests
  • Loading branch information
NewFuture authored Jan 8, 2019
2 parents 3766d94 + 1d850b7 commit 61344de
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dns/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ def request(method, action, param=None, **params):
else:
conn = HTTPSConnection(API_SITE)

if method in ['PUT', 'POST']:
if method in ['PUT', 'POST', 'PATCH']:
# 从public_v(4,6)获取的IP是bytes类型,在json.dumps时会报TypeError
params['content'] = str(params.get('content'))
params = json.dumps(params)
else:
params = urllib.urlencode(params)
else: # (GET, DELETE) where DELETE doesn't require params in Cloudflare
if params:
action = '?' + urllib.urlencode(params)
params = None
conn.request(method, '/client/v4/zones' + action, params,
{"Content-type": "application/json",
"X-Auth-Email": ID,
Expand Down Expand Up @@ -88,7 +90,7 @@ def get_records(zoneid, **conditions):

if not zoneid in get_records.records:
get_records.records[zoneid] = {}
data = request('GET', '/' + zoneid + '/dns_records', per_page=100)
data = request('GET', '/' + zoneid + '/dns_records', per_page=100, **conditions)
if data:
for record in data:
get_records.records[zoneid][record['id']] = {
Expand Down

0 comments on commit 61344de

Please sign in to comment.