Commit aa88d0580308aff20ab25604097a9717b5a799b6

Authored by Imanol-Mikel Barba Sabariego
1 parent e21a568f

Changing request to urlencoded

Showing 1 changed file with 7 additions and 5 deletions
update.py
@@ -7,7 +7,8 @@ import json @@ -7,7 +7,8 @@ import json
7 import argparse 7 import argparse
8 import sys 8 import sys
9 9
10 -CURRENT_VERSION = "1.0-imanolbarba" 10 +CURRENT_VERSION = "1.1-imanolbarba"
  11 +USER_AGENT_STRING = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"
11 DEBUG = 0 12 DEBUG = 0
12 13
13 API_URL="https://domains.google.com/nic/update" 14 API_URL="https://domains.google.com/nic/update"
@@ -86,12 +87,13 @@ def parseResponse(body): @@ -86,12 +87,13 @@ def parseResponse(body):
86 87
87 def updateRecord(username, password, hostname, address, offline): 88 def updateRecord(username, password, hostname, address, offline):
88 msgLog("Updating {} to {}".format(hostname, ("current IP address" if address == None else address)),TYPE_INFO) 89 msgLog("Updating {} to {}".format(hostname, ("current IP address" if address == None else address)),TYPE_INFO)
89 - updateParams = {"hostname" : (None, hostname), "offline": (None, ("yes" if offline == True else "no"))} 90 + headers = {'User-Agent': USER_AGENT_STRING, 'Content-Type': 'application/x-www-form-urlencoded'}
  91 + updateParams = {"hostname" : hostname, "offline": ("yes" if offline == True else "no")}
90 if(address != None): 92 if(address != None):
91 - updateParams["myip"] = (None, address)  
92 - req = requests.Request('POST', API_URL, auth=(username,password), files=updateParams) 93 + updateParams["myip"] = address
  94 + req = requests.Request('POST', API_URL, auth=(username,password), headers=headers, data=updateParams)
93 prep = req.prepare() 95 prep = req.prepare()
94 - msgLog('Request:\n\n{} {}\n{}\n\n{}'.format(prep.method, prep.url,'\n'.join('{}: {}'.format(k, v) for k, v in prep.headers.items()),prep.body.decode()), TYPE_DEBUG) 96 + msgLog('Request:\n\n{} {}\n{}\n\n{}'.format(prep.method, prep.url,'\n'.join('{}: {}'.format(k, v) for k, v in prep.headers.items()),prep.body), TYPE_DEBUG)
95 rep = requests.Session().send(prep) 97 rep = requests.Session().send(prep)
96 msgLog('Response:\n\n{} {}\n{}\n\n{}'.format(rep.status_code, http.client.responses[rep.status_code],'\n'.join('{}: {}'.format(k, v) for k, v in rep.headers.items()),rep.content.decode()), TYPE_DEBUG) 98 msgLog('Response:\n\n{} {}\n{}\n\n{}'.format(rep.status_code, http.client.responses[rep.status_code],'\n'.join('{}: {}'.format(k, v) for k, v in rep.headers.items()),rep.content.decode()), TYPE_DEBUG)
97 if(rep.status_code != 200): 99 if(rep.status_code != 200):