我想和Postman一起做一个RESTAPI测试
我需要遵循的步骤写在
https://github.com/blackboard/BBDN-Collab-Postman-REST
及
https://www.youtube.com/watch?v=-mdRZ_1-Dzg&ab_channel=BbDevSupport
我可以一步一步地从这个地址的视频中了解我需要做什么
我得到这个错误,即使我已经按照所有的步骤
{
"error_description": "Invalid Client Id",
"error": "invalid_client"
}
我确信我要测试的URL、api密钥和密码是正确的,因为当我用代码尝试它时,它是有效的
我有下面的test.py
代码,当我运行这段代码时,我得到了图片中的输出
# Before run this py install requirements.txt
import json
import requests
import time
import jwt
import datetime
from dateutil import tz
import ssl
import sys
import os
key = "Your Key"
secret = "Your Secret"
url = "https://eu-lti.bbcollab.com/collab/api/csa"
headers = {
'typ' : 'JWT',
'alg': "RS256"
}
claims = {
"iss" : key,
"sub" : key,
"exp" : datetime.datetime.utcnow() + datetime.timedelta(minutes = 5)
}
assertion = jwt.encode(claims, secret)
payload = {
'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' : assertion
}
print(assertion)
token_endpoint = url + '/token'
r = requests.post(token_endpoint, data=payload, auth=(key, secret), verify=True)
print("[auth:setToken()] STATUS CODE: " + str(r.status_code) )
#strip quotes from result for better dumps
res = json.loads(r.text)
print("[auth:setToken()] RESPONSE: \n" + json.dumps(res,indent=4, separators=(',', ': ')))
token = ""
if r.status_code == 200:
parsed_json = json.loads(r.text)
token = parsed_json['access_token']
else:
print("can not get token")
exit()
def getRecordings(url, token, limit, offset):
authStr = 'Bearer ' + token
payload = {
'limit' : limit,
'offset': offset
}
args = "&".join(["%s=%s"%(k,v) for k,v in payload.items()])
r = requests.get(url + '/recordings?' + args, headers={ 'Authorization':authStr,'Content-Type':'application/json','Accept':'application/json' }, json=payload, verify=True)
if r.status_code == 200:
res = json.loads(r.text)
#print("Recording: " + json.dumps(res,indent=4, separators=(',', ': ')))
return res
else:
return None
def getRecordingUrl(url, token, id):
authStr = 'Bearer ' + token
r = requests.get(url + '/recordings/' + id + "/url?disposition=download", headers={ 'Authorization':authStr,'Content-Type':'application/json','Accept':'application/json'}, verify=True)
if r.status_code == 200:
res = json.loads(r.text)
return res["url"]
else:
return None
records = getRecordings(url, token, 10, 0)
for rec in records["results"]:
id = rec["id"]
rec_url = getRecordingUrl(url, token, id)
if not os.path.exists("./recordings"):
os.makedirs("./recordings")
if rec_url:
name = "./recordings/" + rec["name"] + ".mp4"
print ("Downloading -> %s" % (name))
r = requests.get(rec_url, allow_redirects=True)
with open(name, 'wb') as f:
f.write(r.content)
test.py
的输出
我的主要目标是下载黑板协作中的记录。当我想和邮递员一起测试时,我失败了
以前有人遇到过这样的问题吗? 我怎样才能解决这个问题
目前没有回答
相关问题 更多 >
编程相关推荐