openwrt Python3.6通过自带的urllib通过get或post方法请求url

# 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)
posted @ 2020-01-16 10:46  K_Code  阅读(639)  评论(0编辑  收藏  举报