标签:方法 ror pytho ons err 接口文档 erro sop lin
import requests
import json
import traceback
"""接口查询"""
def GetSop(url,opid,queryvalue):
"""data_query_payload的配置根据接口文档来"""
data_query_payload={
"authcode":‘111‘
"params":{
"vttype":‘a‘,
"vt":vt
}
}
"""headers根据实际打开的网页头配置"""
headers = {
"Content-Type":"application/json"
}
try:
"""可以使用requests.post().json()来代替以下三行代码"""
reponse = requests.post(url,headers=headers,data=json.dumps(data_query_payload))
r = reponse.text
queryjson = json.loads(r)
res = queryjson[‘data‘]
except:
traceback.print_exc()
res = ‘error‘
return res
"""txt文件读取为列表"""
def TxtToList(infile):
res = []
with open(infile,‘r‘) as f:
for line in f.readlines():
c = line.strip().strip(‘\n‘).split(‘,‘)
res.extend(c)
return res
"""数据存入txt文件"""
with open(outfile,‘w‘) as f:
res = GetSop(url,opid,queryvalue)
if res!=[]:
f.write(str(res)+‘\n‘)
标签:方法 ror pytho ons err 接口文档 erro sop lin
原文地址:https://www.cnblogs.com/bluepotato/p/14097212.html