Closed r13i closed 1 month ago
Hey there, @r13i! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together while we wait for a human maintainer to join the conversation.
The HTTPError: Current user not permitted to use Confluence
error raised by the ConfluenceReader
from Llama Index, while the Atlassian Confluence SDK works fine with the same parameters, could be due to differences in how the authentication and permissions are handled between the two implementations.
In the ConfluenceReader
class, the authentication can be done using OAuth2, API token, or basic authentication (username and password). If the parameters provided do not match the expected format or if there are missing permissions for the user, the ConfluenceReader
might raise an HTTPError
.
Here is a snippet from the ConfluenceReader
class that shows the initialization and authentication process:
def __init__(
self,
base_url: str = None,
oauth2: Optional[Dict] = None,
cloud: bool = True,
api_token: Optional[str] = None,
user_name: Optional[str] = None,
password: Optional[str] = None,
) -> None:
if base_url is None:
raise ValueError("Must provide `base_url`")
self.base_url = base_url
try:
from atlassian import Confluence
except ImportError:
raise ImportError(
"`atlassian` package not found, please run `pip install"
" atlassian-python-api`"
)
self.confluence: Confluence = None
if oauth2:
self.confluence = Confluence(url=base_url, oauth2=oauth2, cloud=cloud)
else:
api_token = api_token or os.getenv(CONFLUENCE_API_TOKEN)
if api_token is not None:
self.confluence = Confluence(url=base_url, token=api_token, cloud=cloud)
else:
user_name = user_name or os.getenv(CONFLUENCE_USERNAME)
if user_name is None:
raise ValueError(
"Must set environment variable `CONFLUENCE_USERNAME` if oauth,"
" oauth2, or `CONFLUENCE_API_TOKEN` are not provided."
)
password = password or os.getenv(CONFLUENCE_PASSWORD)
if password is None:
raise ValueError(
"Must set environment variable `CONFLUENCE_PASSWORD` if oauth,"
" oauth2, or `CONFLUENCE_API_TOKEN` are not provided."
)
self.confluence = Confluence(
url=base_url, username=user_name, password=password, cloud=cloud
)
Ensure that the parameters provided for authentication (OAuth2, API token, username, and password) are correct and that the user has the necessary permissions to access the Confluence instance. Additionally, verify that the base_url
is correctly formatted and includes the /wiki
suffix if required.
If the Atlassian Confluence SDK works fine with the same parameters, it might be worth checking if there are any differences in the permissions or scopes granted to the user when using the SDK versus the ConfluenceReader
.
According to the Llama Index documentation, the base_url
must end with /wiki
, and the CONFLUENCE_PASSWORD
should be an API token obtained from the Atlassian profile security settings. Ensure that these details are correctly configured:
The user needs to specify the base URL for a Confluence instance to initialize the ConfluenceReader - base URL needs to end with `/wiki`. The user can optionally specify OAuth 2.0 credentials to authenticate with the Confluence instance. If no credentials are specified, the loader will look for `CONFLUENCE_API_TOKEN` or `CONFLUENCE_USERNAME`/`CONFLUENCE_PASSWORD` environment variables to proceed with basic authentication. Keep in mind `CONFLUENCE_PASSWORD` is not your actual password, but an API Token obtained here: https://id.atlassian.com/manage-profile/security/api-tokens.
Make sure to follow these guidelines to avoid the HTTPError
[1][2].
To continue talking to Dosu, mention @dosu.
Checked locally, the code
from llama_index.readers.confluence import ConfluenceReader
reader = ConfluenceReader(
base_url='https://example.atlassian.net/wiki',
user_name='user@example.com',
password=CONFLUENCE_API_TOKEN,
)
documents = reader.load_data(
space_key='MY_SPACE',
include_attachments=False,
)
works just fine.
Are you sure you use the right token in the second example?
@skvrd thanks for checking. Yes I'm using the exact same values (same context on a Jupyter notebook) as I shared in the bug description.
@skvrd, also the same credentials work fine with LangChain's Confluence loader:
from langchain_community.document_loaders import ConfluenceLoader
loader = ConfluenceLoader(
url='https://example.atlassian.net/wiki',
username='user@example.com',
api_key=CONFLUENCE_API_TOKEN,
)
documents = loader.load(
space_key='MY_SPACE',
include_attachments=False,
max_pages=50
)
print(len(documents))
// 50
Very strange. Just checked the code again on my end, and it works fine. Here is entire code:
from llama_index.readers.confluence import ConfluenceReader
token = "token goes here"
reader = ConfluenceReader(
base_url="https://site-goes-here.atlassian.net/wiki",
user_name="myemail@example.com",
password=token,
)
documents = reader.load_data(
space_key='SPACE_KEY_GOES_HERE',
include_attachments=False,
)
print(documents)
// Prints fetched documents
What is response of this pip freeze | grep atlassian
?
Ok, I think I found the issue:
inside ConfluenceReader
:
api_token = api_token or os.getenv(CONFLUENCE_API_TOKEN)
if api_token is not None:
self.confluence = Confluence(url=base_url, token=api_token, cloud=cloud)
So basically if CONFLUENCE_API_TOKEN is set, it will use following type of auth: Confluence(url=base_url, token=api_token, cloud=cloud)
and ignore the provided user_name and password.
Great finding @skvrd , unsetting the environment variable actually solves it:
del os.environ['CONFLUENCE_API_TOKEN']
... but is this behaviour desirable? I guess priority should be given to ALL the variables provided by the user, and if not the logic should fall back to checking the environment variables?
Referring specifically to this snippet in the README:
If no credentials are specified, the loader will look for CONFLUENCE_API_TOKEN or CONFLUENCE_USERNAME/CONFLUENCE_PASSWORD environment variables to proceed with basic authentication.
@skvrd I'm proposing the following PR for fixing: https://github.com/run-llama/llama_index/pull/14905 cc @nerdai
Issue resolved in the release version 0.1.7
(https://github.com/run-llama/llama_index/pull/14905).
Bug Description
I am trying to fetch Confluence documents using API tokens, and the fetch works fine using the Atlassian Confluence SDK
atlassian-python-api
:However, using the same parameters in the
ConfluenceReader
from Llama Index mapped behind the scenes to the exact same parameters in the Atlassian SDK:I get
HTTPError: Current user not permitted to use Confluence
.Version:
Version
0.10.55
Steps to Reproduce
See description above
Relevant Logs/Tracbacks