Forums

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

get_page_by_id(page_id, expand='body.storage') returns string, instead of a dictionary

Rajesh Vr October 21, 2022
confluence = Confluence(url=conf_site, username=conf_user, password=conf_passwd)
pg = confluence.get_page_by_id(page_id, expand='body.storage')
pg_content = pg['body']
pg_content = pg['body'] throws error as:
page_content = page['body']
TypeError: string indices must be integers


Can you please help me to fix this issue?

 

1 answer

0 votes
Peter Van de Voorde
Community Champion
October 21, 2022

Hi @Rajesh Vr 

Welcome to the Atlassian Community.

Can you please try

pg_content = pg.body instead of pg_content = pg['body']


Cheers,
Peter

Rajesh Vr October 21, 2022

I tried with: 

pg.body, but got the following error:

AttributeError: 'str' object has no attribute 'body'

Peter Van de Voorde
Community Champion
October 21, 2022

Ok, 

So basically pg is your body content in json format then already.
Can you try using the json python library like explained here: https://www.w3schools.com/python/python_json.asp 

To turn this string into a dictionary?

Cheers,
Peter

Rajesh Vr October 22, 2022

I tried the json, but with no luck :-(

 

p = json.loads(page) itself throws json Decode error.

Then I directly used:
table = pandas.read_html(page) which throws error:
raise ValueError("No tables found")
ValueError: No tables found

My goal is to read a table from confluence page and update. 

Rajesh Vr October 24, 2022

Could anyone please share example code snippet for reading and updating Confluence page tables using python/or any other methods?

Peter Van de Voorde
Community Champion
October 25, 2022
Rajesh Vr October 26, 2022

hello @Peter Van de Voorde ,

I had already referred the first link in your list, and researched a few more similar sites, but without success.

Let me now try using REST APIs directly after referring other links in your list. I will update here in case I have something to share. 

cheers,

-Rajesh

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events