码迷,mamicode.com
首页 > 编程语言 > 详细

python requests post和get

时间:2019-03-25 19:03:17      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:ade   pos   robot   cache   round   header   passwd   .com   ken   

 

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)

 

python requests post和get

标签:ade   pos   robot   cache   round   header   passwd   .com   ken   

原文地址:https://www.cnblogs.com/sea-stream/p/10595558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!