Confluence Python API

VisshnuVandith G June 9, 2020

Hello. I’ve tried installing using pip install atlassian-python-api, but when I write the script, python is giving me ModuleNotFoundError: No module named ‘atlassian’ when I run my Script.Please Help. Thanks in Advance.
Reference link: https://atlassian-python-api.readthedocs.io/index.html

This is the code.

from atlassian import Confluence

confluence = Confluence(
url=‘http://localhost:8090’,
username=‘admin’,
password=‘admin’)

status = confluence.create_page(
space=‘DEMO’,
title=‘This is the title’,
body=‘This is the body. You can use HTML tags!’)

print(status)

2 answers

1 vote
Dave Chevell
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 19, 2020

The error you're receiving indicates that, wherever you may have installed the package, it's not in the python installation that you're using to run the script.

If you have python 2 and python 3 installed, you may have used the pip from one installation whilst you're running the script with the other. 

The easiest thing to check is to run which pip and which python (or which python3, whichever is the binary that you used when you tried running the script). Are they in the same place? If not, then that explains why: the python you're running is from a different installation than the pip you used to install.

As a general rule I would recommend using virtual environments, as this simplifies everything and ensures you're using a default python local to your project:

mkdir my_project && cd my_project
python3 -m venv .env #this creates a virtual environment in the folder ".env"
source .env/bin/activate
pip3 install atlassian-python-api
python3 myscript.py

If you take this approach you should be guaranteed to be using the right python and pip from the virtual environment installation and you shouldn't get the module import error.

1 vote
Osimar Medeiros
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 11, 2020

You may have to use python3 instead of python2 or python (if python2 is the default on your OS).

I tested it (same script) and I was able to create the page by either calling the script with python3 or setting the shebang in the script's first line pointing it to 

#!/usr/bin/python3

Can you confirm if the script runs when calling it with python3?

Dave Chevell
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 19, 2020

atlassian-python-api is compatible with python 2 and python 3. You're not far off though - it's likely because the wrong python installation is being used, rather than the wrong python version.

Like k040394000 likes this
mini trivedi January 11, 2021

thanks @Osimar Medeiros it did work while running it with "python3 <script>"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events