atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 642 forks source link

[confluence] SSLerror and 401 #1364

Closed chkp-sgrimes closed 2 months ago

chkp-sgrimes commented 2 months ago

I would appreciate any clues about how to resolve either error, this looks like a great way to audit our confluence implementation!

  1. SSLError I installed atlassian-python-api, python 3.11, in a venv on Windows 10. My computer is connected via VPN through a firewall that inspects ssl/ tls traffic offering its own certificate.

confluence = Confluence(url="host", username="user", password="token", verify_ssl=False)

Initially, I was able to login using my personal access token and I receive the full confluence object. When I tried to call any confluence method such as confluence.get_page_by_id(page_id="369271800") I received

requests.exceptions.SSLError: HTTPSConnectionPool(host='host': Max retries exceeded with url: /confluence/rest/api/content/369271800 (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)')))

  1. 401 I then tried to resolve the SSLError by (venv)$ pip install --trusted-host pip-system-certs Now, I am still able to successfully initialize a confluence object but am receiving the following error

    File "C:\Users\\PycharmProjects\confluence-3.11.venv\Lib\site-packages\atlassian\confluence.py", line 346, in get_page_by_id response = self.get(url, params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\\PycharmProjects\confluence-3.11.venv\Lib\site-packages\atlassian\rest_client.py", line 340, in get response = self.request( ^^^^^^^^^^^^^ File "C:\Users\\PycharmProjects\confluence-3.11.venv\Lib\site-packages\atlassian\rest_client.py", line 312, in request self.raise_for_status(response) File "C:\Users\\PycharmProjects\confluence-3.11.venv\Lib\site-packages\atlassian\confluence.py", line 3261, in raise_for_status raise HTTPError("Unauthorized (401)", response=response) requests.exceptions.HTTPError: Unauthorized (401)

chkp-sgrimes commented 2 months ago

curl with my token is successful

  1. curl -H "Authorization: " <https:///rest/api/content {"results":[
  2. curl -H "Authorization: " https:///rest/api/content/369271800/descendant/attachment {"results":[{"id":"516876237",
chkp-sgrimes commented 2 months ago

Solved using different authentication. requirements.txt below

import requests from atlassian import Confluence

def main() -> None: confluence: Confluence

s = requests.Session()
s.headers['Authorization'] = 'Bearer <token>'

confluence = Confluence(url="<base url>", session=s)

pg = confluence.get_page_by_id(page_id="369271800")
print("bye")

if name == 'main': main()

pip list Package Version


atlassian-python-api 3.41.11 beautifulsoup4 4.12.3 certifi 2024.2.2 charset-normalizer 3.3.2 Deprecated 1.2.14 idna 3.6 jmespath 1.0.1 oauthlib 3.2.2 packaging 24.0 pip 24.0 python-certifi-win32 1.6.1 #I'm on windows requests 2.31.0 requests-oauthlib 2.0.0 setuptools 68.2.0 setuptools-scm 8.0.4 six 1.16.0 soupsieve 2.5 typing_extensions 4.11.0 urllib3 2.2.1 wheel 0.41.2 wrapt 1.16.0