zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    CUDA[2] Hello,World
    mysql操作
    virsh 连接虚拟机 (vnc 或 控制台)
    ssh访问流程
    使用ceph-deploy进行ceph安装
    openstack 的horizon的结构
    django 后台格式化数据库查询出的日期
    web 应用的部署
    工具
    python性能优化
  • 原文地址:https://www.cnblogs.com/z3286586/p/12200059.html
Copyright © 2011-2022 走看看