Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a connection using Confluence API and Python.

Kompal Sithta June 9, 2025

I am trying to develop a connection with the confluence pages using api but I am getting an error again and again:

 

ConnectionError: HTTPSConnectionPool(host='confluence.hrs.io', port=443): Max retries exceeded with url: /rest/api/content (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f9e571e3370>: Failed to resolve 'confluence.hrs.io' ([Errno -2] Name or service not known)"))

 I need solution for creating a successful connection using the API.

 

Thanks,

Kompal 

3 answers

0 votes
Kompal Sithta June 9, 2025

I corrected the VPC issue but now I have issue with the authorization its throwing an error - 401. I am using my email id and created api token. Here is the code for that:

 

email = "my email" # Your Atlassian email
api_token = "api token created"
base_url = "company url"
space_key = "key"
page_title = "title"


headers = {
"Authorization": "Basic api token",
"Content-Type": "application/json"
}

response = requests.get(url, headers=headers)

# Display the response
print("Status Code:", response.status_code)
print("Response:", response.json() if response.ok else response.text)

Kompal Sithta June 9, 2025
Kai Krause
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2025

Hi,
have you setup https://developer.atlassian.com/cloud/confluence/basic-auth-for-rest-apis/#supplying-basic-auth-headers the token like written here ? The base64 encoded string , peoviding email adress and generated api token ? 

BR

Kai 

Kompal Sithta June 9, 2025
Kai Krause
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2025

Hi,

To access Confluence REST APIs using Basic Authentication, you need to include an Authorization header in your HTTP requests.

This header should contain the word "Basic" followed by a base64-encoded string of your email adress and token in the format username:token and encode it to base64.  The generated string you can use in your headers as token 

Hoiw you can generate it its written under the link https://developer.atlassian.com/cloud/confluence/basic-auth-for-rest-apis/#supplying-basic-auth-headers

BR
Kai 

0 votes
Kompal Sithta June 9, 2025

Thanks for your response:

I tried to check pt 1:

  • Verify the URL and your network connection: The url on the UI of confluence page is the same as displayed.
  • Check for DNS issues and firewall settings:how do I do this?
Kai Krause
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2025

here is hoiw you can perform a quick DNS-check for your Confluence URL 

Open Command Prompt
Press Win + R → type cmd → Enter.

Run nslookup
nslookup confluence.hrs.io/wiki


There must be  one or more IP addresses shown → DNS is resolving the name.
if can’t find the name isn’t known to the DNS server you’re using.

Inside the corporate network (or over VPN): your PC asks internal DNS servers and traffic must be allowed through internal firewalls to port 443 on the Confluence.


Outside the network without VPN: the hostname must exist in public DNS and the Confluence IP must accept inbound HTTPS from the Internet.

With nslookup you can confirm the name is visible to the DNS server you’re currently using, and your network location (LAN, VPN, or public Internet) determines which DNS server answers and whether firewalls permit the connection.

ive you use a not public environment, you should contact your network administrator to find out, why you cant reach your confluence

BR
Kai

0 votes
Kai Krause
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2025

Hi and welcome ,

The error message you're encountering indicates that your Python script is unable to resolve the hostname. Could be Incorrect URL or Network Issues or DNSA Problems

Here is a simple example to use pyhton to connect to the api 


import requests
from requests.auth import HTTPBasicAuth

# Replace with your Confluence credentials and URL
username = 'your_username'
api_token = 'your_api_token' # Use an API token instead of a password
url = 'https://confluence.hrs.io/rest/api/content'

# Make the request
try:
response = requests.get(url, auth=HTTPBasicAuth(username, api_token))
response.raise_for_status() # Raise an error for bad responses
print(response.json()) # Print the JSON response
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")


i think 

  • Verify the URL and your network connection.
  • Check for DNS issues and firewall settings.

    BR
    Kai 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events