requests.exceptions.HTTPError:401客户端错误atlassian python api

requests.exceptions.HTTPError:401客户端错误atlassian python api,python,confluence,confluence-rest-api,atlassian-python-api,Python,Confluence,Confluence Rest Api,Atlassian Python Api,我正在尝试使用API上的python包装器连接到汇流页面(因为我对这些都不熟悉),但我一直遇到以下错误: requests.exceptions.HTTPError: 401 Client Error 我知道人们说这是因为需要使用API令牌,但页面运行在旧版本的Confluence上,我被告知我们不能使用访问令牌 有人有其他想法吗?下面是一个小代码: from atlassian import Confluence confluence = Confluence( url='http

我正在尝试使用API上的python包装器连接到汇流页面(因为我对这些都不熟悉),但我一直遇到以下错误:

requests.exceptions.HTTPError: 401 Client Error
我知道人们说这是因为需要使用API令牌,但页面运行在旧版本的Confluence上,我被告知我们不能使用访问令牌

有人有其他想法吗?下面是一个小代码:

from atlassian import Confluence

confluence = Confluence(
    url='https://address',
    username='name',
    password='pwd'
    )

confluence.create_page(
    space='Test',
    title='A title',
    body='something')

我曾尝试使用较旧版本的atlassian python api,以防出现冲突,但它导致了相同的错误。

您的代码看起来正常。在不生成API令牌afaik的情况下,使用基本身份验证对Confluence进行身份验证应该是可行的

然而,
401
状态明确表明身份验证存在问题。出现这种情况的明显原因当然是错误的凭据,但我假设您在使用浏览器以交互方式登录confluence时已仔细检查凭据是否有效

为了更好地了解错误,可以
导入日志记录
调试请求和响应:

from atlassian import Confluence
import logging

logging.basicConfig(filename='conf_connect.log', filemode='w', level=logging.DEBUG)

try: 
    c = Confluence(url='https://conf.yoursystem.com', username='name', password='pwd')
    # atlassian API does not raise error on init if credentials are wrong, this only happens on the first request
    c.get_user_details_by_username('name')

except Exception as e:
    logging.error(e)
Confluence
模块内部也使用
日志记录
,因此请求和响应将显示在您的
conf\u connect.log
日志文件中:

DEBUG:atlassian.rest_client:curl --silent -X GET -H 'Content-Type: application/json' -H 'Accept: application/json'  'https://conf.yoursystem.com/rest/api/user?username=name'
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): conf.yoursystem.com:443
DEBUG:urllib3.connectionpool:https://conf.yoursystem.com:443 "GET /rest/api/user?username=name HTTP/1.1" 401 751
DEBUG:atlassian.rest_client:HTTP: GET rest/api/user -> 401 
DEBUG:atlassian.rest_client:HTTP: Response text -> <!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Basic Authentication Failure - Reason : AUTHENTICATED_FAILED</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p><hr class="line" /><h3>Apache Tomcat/9.0.33</h3></body></html>
ERROR:root:401 Client Error:  for url: https://conf.yoursystem.com/rest/api/user?username=name
DEBUG:atlassian.rest\u客户端:curl--silent-X GET-H'内容类型:application/json'-H'接受:application/json''https://conf.yoursystem.com/rest/api/user?username=name'
调试:urllib3.connectionpool:启动新的HTTPS连接(1):conf.yoursystem.com:443
调试:urllib3.connectionpool:https://conf.yoursystem.com:443 “GET/rest/api/user?username=name HTTP/1.1”401751
调试:atlassian.rest\u客户端:HTTP:getrest/api/user->401
调试:atlassian.rest_客户端:HTTP:Response text->HTTP Status 401–未经授权的正文{font family:Tahoma,Arial,sans serif;}h1,h2,h3,b{color:white;背景色:{525D76;}h1{font size:22px;}h2{font size:16px;}h3{font size:14px;}p{font-size:12px;}a{color:黑色;}。行高:1px;背景色:}HTTP状态401–未经授权的
类型状态报告

消息基本身份验证失败-原因:已验证的\u失败

说明请求未被应用,因为它缺少目标资源的有效身份验证凭据。


Apache Tomcat/9.0.33 错误:根目录:401客户端错误:对于url:https://conf.yoursystem.com/rest/api/user?username=name
响应主体可能包括有关原因的一些信息:

HTTP Status 401–未经授权的类型状态报告

消息基本身份验证失败-原因:已验证的\u失败

说明请求未被应用,因为它缺少目标资源的有效身份验证凭据

验证失败的原因表明您的凭据可能有问题。如果您想更深入地了解这一点,还可以使用来显示随请求一起发送的标题

但是,如果您的原因是
AUTHENTICATION\u DENIED
则问题可能如下:如果一行中有太多失败的身份验证尝试,则会触发验证码质询,并且在重置失败的登录计数之前,将发生此错误。当您开发脚本并经常测试它时,这很容易发生。要解决此问题,请打开浏览器并手动(重新)登录到Confluence,完成验证码,或者