我是python新手,不知道如何执行以下操作。 我想把一个变量放在一个命令中,但它不起作用。命令使用的是变量名而不是其值。在
下面的脚本使用用户名和密码调用https来获取令牌。我的令牌被退回。然后我需要使用令牌来创建一个用户。 我有问题,iplanet对中的“token”没有得到正确的扩展。它设置正确,因为我可以在命令之前打印出来。所以token将包含类似“AQIC5wM2LY4Sfcydd5smOKSGJT”的内容,但是当第二个http调用被传递时,传递的是单词token,而不是tokens值。在
import requests
import json
url = "https://www.redacted.com:443/json/authenticate"
headers = {
'X-Username': "user",
'X-Password': "password",
'Cache-Control': "no-cache",
}
response = requests.request("POST", url, headers=headers)
tokencreate = json.loads(response.text)
token=tokencreate['tokenId']
print token
url = "https://www.redacted.com:443/json/users"
querystring = {"_action":"create"}
payload = "{\r\n\"username\":\"Patrick\",\r\n\"userpassword\":\"{{userpassword}}\",\r\n\"mail\":\"patrick@example.com\"\r\n}"
headers = {
'iPlanetDirectoryPro': "token",
'Content-Type': "application/json",
'Cache-Control': "no-cache",
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
这是因为当你打算传递变量令牌时,你传递的是字符串令牌
在这里创建令牌:
但是你不用实际的变量,它应该是这样的:
^{pr2}$相关问题 更多 >
编程相关推荐