zoukankan      html  css  js  c++  java
  • python requests post和get

    import requests
    import time
    import hashlib
    import os
    import json
    from contextlib import closing
    import datetime
    
    def md5_passwd(str,salt=''):
        str=str+salt
        md = hashlib.md5()
        md.update(str.encode())
        res = md.hexdigest()
        return res
    
    
    #get token
    url = "https://api.xxx.com/auth/token"
    appsecret="71fc0b31ab7945f2d0dcf5927db754ba"
    appid="xxx"
    ts=int(round(time.time() * 1000))
    querystring = {"appid":"xxx","timestamp":ts,"sign":md5_passwd(appid+appsecret+str(ts))}
    headers = {"Content-Type":"application/x-www-form-urlencoded",'cache-control': "no-cache"}
    response = requests.post(url, headers=headers,data=querystring)
    token_api=response.json()["data"]["token"]
    
    #get msg
    headers["Authorization"]="Bearer "+token_api
    url="https://api.xxx.com/openapi/robots/applications/versions/latest"
    querystring = {"no":"xx-V1A1-00001","appkey":"HDb9aafb189b34b289","type":3}
    response = requests.get(url, headers=headers,params=querystring)
    res=response.json()
    file_url=res["data"]["url"]
    file_v=res["data"]["version"]
    print(res)
  • 相关阅读:
    结对编程
    四则运算
    认清自我,创造未来!!!
    浅谈GIT
    典型用户及用例故事
    结对编程 四则运算
    四则运算
    《未来的程序员》
    java项目命名规范
    四则运算测试
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10595558.html
Copyright © 2011-2022 走看看