# coding = utf-8
import uuid
import hashlib
import time
import ssl
from urllib import request
from urllib import parse
ssl._create_default_https_context = ssl._create_unverified_context
def header_Md5(Nonce, CTime):
header_key = "XXXXXXXXXXXXXXXX"
obj = hashlib.md5((Nonce + CTime + header_key).encode('utf-8'))
return obj.hexdigest()
URL = 'https://XXXXXXXXX.com/Gateway/SmartHome/XXXXXX'
Nonce = "12saP2wA13"
CTime = str(int(time.time()))
headers = {"User-Agent":"test request headers","Nonce": Nonce,"CTime": CTime,"Sign": header_Md5(Nonce,CTime)}
body ={"gwName": "test","gwid": '6699'+uuid.uuid1().hex[-12:], "Password":"123" }
body = parse.urlencode(body).encode('utf-8')
req = request.Request(URL, headers=headers, data=body) # POST方法
# req = request.Request(url+params) # GET方法
page = request.urlopen(req).read()
page = page.decode('utf-8')
print("revc data :",page)