目前我收到错误400状态代码
我迷失在我需要做的事情上。状态代码400与语法有关。如何将输出格式化为JSON文件格式?
import requests, json, urllib3
urllib3.disable_warnings()
url = 'https://symantecwebsite:8446/sepm/api/v1/identity/authenticate'
cert_location = 'newsymanteccert.cer'
headers = {'Content-Type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, verify=cert_location, auth=('myusername','password*-uTem'),
headers=headers)
print r.status_code
如果我改变最后一行打印json.dumps,我明白了 "函数转储在0x03D349B0"
获取输出答案 0 :(得分:1)
这个派对迟到了,但我遇到了几乎相同的python同样的问题。那么,我的问题最终是我的密码中的特殊字符。在Symantec管理器端处理身份验证的其余方法并不知道如何处理某些特殊字符,因此它返回400语法错误。尝试从您的密码中提取特殊字符,并将其保留在15个字符以内。
答案 1 :(得分:0)
我可能无法给你一个完整的答案,但我读了你链接的PDF。第一步是从对Symantec Endpoint Protection Manager进行身份验证
下的章节中获取有效令牌e.g。 “令牌”:“c34692c5-201d-4d94-b0f8-61ed03383337”
我的猜测是你需要传递字典:
urldata = {
"username" : "admin",
"password" : "password",
"domain" : ""
}
headers = {"Content-Type": "application/json"} # not 100% sure here but looks like you need to send headers too
response = requests.post(url, data = urldata, headers = heaaders) # gets data
rdata = json.loads(response.text) # loads data into a dictionary
mytoken = rdata["token"] # saves token to mytoken variable
答案 2 :(得分:0)
我使用以下方法来获取身份验证:
import requests
import urllib3
import json
link ="https://YOUR_IP:8446/sepm/api/v1/"
data = { "username" : "admin", "password" : "password", "domain" : ""} #this is the login details required for the server
data = json.dumps(data)
headers = {"Content-Type":"application/json"}
urllib3.disable_warnings() #this is a patch to allow calls to SSL certs even if they cannot be verified
initialRequests = requests.get(link + "version", verify=False)
initialRequests = requests.post(link + "identity/authenticate", headers=headers, data=data, verify=False) #This requests an authentication from SEPM
api_token = (initialRequests.json()["token"]) #this uses the above line to get and store the token required for authenticated commands