Code Monkey home page Code Monkey logo

Comments (5)

ashishpatel1992 avatar ashishpatel1992 commented on July 4, 2024

You should open file as wb instead of w
wb allows files to be opened for writing as binary

from atlassian-python-api.

Kruttifrutti avatar Kruttifrutti commented on July 4, 2024

You should open file as wb instead of w wb allows files to be opened for writing as binary

Thanks for helping out, unfortunately, I am still getting a corrupted file...

from atlassian-python-api.

ashishpatel1992 avatar ashishpatel1992 commented on July 4, 2024

Quick check on this, I have tested the code and it is able to generate the pdf for me.
Possibly you need to first check if authentication is working correctly or not.

Sharing the code snippet which worked for me

from atlassian import Confluence

def save_file(content, title):
    file_pdf = open(title + ".pdf", "wb")
    file_pdf.write(content)
    file_pdf.close()
    print("Completed")

secret_key="<your_confluence_secret_key>"
label = "apitesting"
confluence = Confluence(
        url='https://<your_confluence_url>',
        token=secret_key)
pages = confluence.get_all_pages_by_label(label=label, start=0, limit=10)
for page in pages:
    response = confluence.get_page_as_pdf(page["id"])
    save_file(content=response, title=page["title"])

Also I have used adobe acrobat to verify the files

from atlassian-python-api.

frankiedrake avatar frankiedrake commented on July 4, 2024
label

I have a problem with the export API.
I did provide a token and I can successfully get page content etc., but export to pdf returns the HTML content of a login page.
Here's my code:

confluence = Confluence(
    url='https://my.company.confluence/',
    token=token)

page = confluence.get_page_by_id(11111, expand='body.storage') # WORKS WELL
print(page['title'])

response = confluence.get_page_as_pdf(68258487)
print(response) # PRINTS Login page content

from atlassian-python-api.

ashishpatel1992 avatar ashishpatel1992 commented on July 4, 2024

@frankiedrake It could be possible that your confluence API url is incorrect. thats why you are seeing Login page as HTML result.
Check with your administrator for correct url.

from atlassian-python-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.