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)
  • 相关阅读:
    Markdown自动生成目录
    defer使用小结
    RESTful API设计的点
    总结下数据库的命名规范
    go module学习笔记
    golang环境安装和配置
    jenkins环境搭建&配置(二)
    mac环境搭建selenium
    sed命令
    测试工作遇到的自动补0
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10595558.html
Copyright © 2011-2022 走看看