Python/Res中的身份验证问题

2024-06-25 23:39:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题是,我不断得到一个“回复[401]”,从我在网上看到的情况来看,这意味着存在身份验证错误。我正在尝试通过python中的Rest调用创建一个新用户。我对Python/Rest还很陌生,所以我确信我缺少了一些东西。你知道吗

下面是我的代码:

import requests
import json
import base64

print("Script Running")
username = ‘UN’
password = ‘PW’
tempString = username + ':' + password
encodedString = base64.b64encode(tempString.encode())
data = {"name": "changeUser", "password": "12345","emailAddress": "emailaddress@some.com","displayName": "changeUser","notification" : "false"}
url = "http://myserver.atlassian.net/rest/api/2/user/"
headers = {'Authentication': 'Basic ' + tempString, 'Content-type': 'application/json', 'Accept': 'application/json', 'X-Atlassian-Token': 'no-check' }

print(encodedString)
r = requests.post(url, json.dumps(data), headers)
print(r)
print("Script Ending")

encodedString返回b'stringofstuff=' print(r)返回响应[401]


Tags: importrestjsonurldatausernamescriptpassword
2条回答

您是否使用了单独的HTTP客户机来进行此调用?试着用邮递员用相同的数据打电话,这样你就可以决定先从哪里开始寻找。你知道吗

还有-你到底要用编码环做什么?你只能在打印通话中使用它。你知道吗

请求具有所有这些的选项。我只想用

r = requests.post(url, json=data, auth=(username, password))

相关问题 更多 >