Using atlassian python confluence with microsoft authenticated account?
Asked by Stephen Ellwood:

I am an experienced python coder and want to access Confluence via Python. I wrote a simple 2 line script to test that I had access and found that I had not

```

from atlassian import Confluence

confluence = Confluence(
url='https://my_company.atlassian.net/wiki/home',
username='stephen.ellwood@my_company.com',
password='my_password')
confluence.get_all_spaces(start=0, limit=500, expand=None)
```

I get the result:

```
HTTPError: 401 Client Error: Unauthorized for url: https://my_company.atlassian.net/wiki/home/rest/api/space?limit=500
```

I am using the correct username and password but they are my Microsoft credentials; I do not have a direct confluence account.

Is there a different authentication method for users who use Microsoft Authenticated accounts?


Answers:
author: Thomas Deiler
body: Dear [@Stephen Ellwood](/t5/user/viewprofilepage/user-id/4227781) ,

that won't work. Basic auth is not allowed anymore for cloud. You need to take the Api token for the 'password', instead.

```
password='rahHWQ61rElyFHmsz9H6ABv')
```

You can generate your own Api token here: <https://id.atlassian.com/manage-profile/security/api-tokens>

So long

Thomas

comments: author: Stephen Ellwood
body: Thanks, I was confused by the use of the name password instead of the name token. Working now!


author: Thomas Deiler
body: Dear [@Stephen Ellwood](/t5/user/viewprofilepage/user-id/4227781) ,

'user' and 'password' are just variable names in your Python function *Confluence()*. You could rename them to 'email' and 'token'. The effect will be the same.

So long

Thomas


author: Stephen Ellwood
body: Hi [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715) understood that "user" and "password" are \[optional\] parameter names for the Confluence Class instance creator. Several instance methods are described some using the parameter "password" and others using the parameter "token".

While I completely agree with "that which we call a Rose by any other name would smell as sweet" and am in no way wanting to sound defensive but in this case I saw "token" and "password" not used interchangeably so did not think to do so.

Thanks again for your help. Pleased it was so easy to solve.


author: Kamal Ali
body: I am having a similar error:

```
401 Client Error:  for url https://confluence.company.com/rest/api/content/search?cql=QUERY.
```

Initially, I generated a conflucene token from here (<https://confluence.company.com/plugins/personalaccesstokens/usertokens.action>) and used that for the password.

Then, I tried following the solution above by generating an Atlassian token and passing it in for the password, but I am still getting this error.

However, my error statement does not say "Unauthorized".

If I try to provide a wrong password, I also get the same error message.

[@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715) Your help is much appreciated.


author: Thomas Deiler
body: Dear [@Kamal Ali](/t5/user/viewprofilepage/user-id/5033139) ,

do you user Confluence Cloud or Server? For Cloud the request looks like this:

```
https://company-name.atlassian.net/wiki/rest/api/content/search?cql=QUERY
```

for more details: <https://developer.atlassian.com/cloud/confluence/rest/api-group-content/#api-wiki-rest-api-content-search-get>

So long

Thomas


author: Karthik PANICKER
body: Hi [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715)   

I am using the confluence server, and want to do auth using my msft credentials, how would you suggest I do that in python ?


author: Stephen Ellwood
body: Hi [@Karthik PANICKER](/t5/user/viewprofilepage/user-id/5481274)

I am not sure if the mechanism is the same on the server instance (as apposed to the cloud instance) but it is the process for Cloud instance that is discussed here. It could be that you can literally use your username and password on the Server instance or it could be that there is a way of generating a token for access in the same way as on the cloud.


Tags: authentication

cloud

confluence-cloud

python