使用tetpyclient发出POST请求时,为什么会出现403错误?

时间:2020-09-08 12:30:15

标签: python python-3.x python-2.7 api cisco

尝试使用其tetpyclient在Cisco Tetration API中发出POST请求。使用get请求时收到200响应,但是使用json过滤器进行POST请求以查询流时返回403。我的json数据语法不正确还是python中存在语法错误?

from tetpyclient import RestClient
import urllib3
import json
import requests
from datetime import datetime
from flask import *
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

API_ENDPOINT = "https://"
restclient = RestClient(API_ENDPOINT, credentials_file = 'path/to/credentials.json', verify = False)
get = restclient.get("/flowsearch/metrics")
print (get.status_code) ##to test if api can be reached

req_payload = {"t0": "2020-08-01T09:00:00-0700",
               "t1": "2020-08-01T10:00:00-0700",
               "scopeName": "Default",
               "limit": 10,
               "filter": {                  
                  "type": "and",
                  "filters": [
                     {"type": "eq", "field": "src_address","value": "00.000.0.000" },
                     {"type": "eq", "field": "dst_address","value": "000.000.00.00" }
                   ]
}
}

resp = restclient.post('/flowsearch', json_body=json.dumps(req_payload))

print(resp.content)
print (resp.status_code)

if resp.status_code == 200:
   parsed_resp = json.loads(resp.content)
   print (json.dumps(parsed_resp, indent=4, sort_keys=True))

感谢所有反馈! 以下是链接到Fourtion API文档的链接:https://www.cisco.com/c/en/us/td/docs/security/workload_security/tetration-analytics/sw/config/b_Tetration_OpenAPI/m_flow-search.html

1 个答案:

答案 0 :(得分:1)

HTTP 403是HTTP状态代码,表示出于某种原因禁止访问所请求的资源

您似乎无法使用您使用的凭据呼叫/flowsearch