It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unable to upload an attachment on confluence page using oauth authentication, it works using basic a

Hi, 
 I created an application link on Confluence and  am able to get the token and secret for oauth. When I try to use the token/secret in the Atlassain Confluence python api, it doesn't work. I am able to upload an attachment using basic authentication.

Here is my code

import requests
from requests_oauthlib import OAuth1
from oauthlib.oauth1 import SIGNATURE_HMAC, SIGNATURE_RSA
from requests_oauthlib import OAuth1Session
from atlassian import Confluence




key = open("confluence_privatekey.pem").read()
pkeystring=key.strip()
print (pkeystring)
oauth = OAuth1Session('oauthkey', client_secret='oauthsecret',signature_method=SIGNATURE_RSA, rsa_key=pkeystring)

####this call is working
fetch_response = oauth.fetch_request_token('https://xyz.atlassian.net/wiki/plugins/servlet/oauth/request-token')


access_token = fetch_response.get('oauth_token')
access_token_secret = fetch_response.get('oauth_token_secret')
print(fetch_response)
oauth_dict = {
'access_token': access_token,
'access_token_secret': access_token_secret,
'consumer_key': 'oauthkey',
'key_cert': pkeystring}
print(oauth_dict)



confluence = Confluence(url='https://xyz.atlassian.net/wiki', oauth=oauth_dict)


### this call fails but works with basic authentication
zz = confluence.attach_file("text1.txt", name='text1.txt', page_id='1234')

I get this error:


File "C:\Users\dbhatia\PycharmProjects\LearnModule\venv\lib\site-packages\atlassian\confluence.py", line 522, in attach_file
comment=comment)
File "C:\Users\dbhatia\PycharmProjects\LearnModule\venv\lib\site-packages\atlassian\confluence.py", line 484, in attach_content
if attachments.get('size'):
AttributeError: 'str' object has no attribute 'get'

 

1 answer

0 votes

Hi Deepika,

I would suggest reaching out to the Developer Community:

https://community.developer.atlassian.com/

There you will be able to get better support for your development queries.

Cheers,

Paulo

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

How is your team having fun and bonding, remotely, utilizing Confluence?

Thanks everyone for answering last week’s question. The winner of the random drawing from those who commented is: @LarryBrock I’ll contact you separately with your prize details. This wee...

283 views 9 7
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you