Forums

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

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

Deepika Bhatia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 10, 2020

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
Paulo F.
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 13, 2020

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
AUG Leaders

Atlassian Community Events