Comments (3)
Saw people reporting this issue but haven't found a resolution
from atlassian-python-api.
Let me check that end point on cloud
from atlassian-python-api.
The endpoint has changed from /services/api/v1/task/<TASK_ID>/progress
to /rest/api/longtask/<TASK_ID>
.
See API doc: Get long-running task
I solved this in my code by sub-classing the Confluence
class and overwriting the two methods Confluence.get_page_as_pdf()
and Confluence.get_pdf_download_url_for_confluence_cloud()
.
I just copied the original method bodies and ajusted the code.
In Confluence.get_page_as_pdf()
:
@@ -55,7 +54,7 @@ class CustomConfluence(Confluence):
url = "spaces/flyingpdf/pdfpageexport.action?pageId={pageId}".format(
pageId=page_id
)
- if self.api_version == "cloud":
+ if self.cloud:
url = self.get_pdf_download_url_for_confluence_cloud(url)
if not url:
log.error("Failed to get download PDF url.")
@@ -63,8 +62,6 @@ class CustomConfluence(Confluence):
"Failed to export page as PDF",
reason="Failed to get download PDF url.",
)
- # To download the PDF file, the request should be with no headers of authentications.
- return requests.get(url, timeout=75).content
return self.get(url, headers=headers, not_json_response=True)
In Confluence.get_pdf_download_url_for_confluence_cloud()
:
def get_pdf_download_url_for_confluence_cloud(self, url):
@@ -86,27 +83,38 @@ class CustomConfluence(Confluence):
task_id = response_string.split('name="ajs-taskId" content="')[1].split(
'">'
)[0]
- poll_url = "/services/api/v1/task/{0}/progress".format(task_id)
+ poll_url = "/rest/api/longtask/{0}".format(task_id)
+ task_timeout = time.monotonic() + 180
while running_task:
log.info("Check if export task has completed.")
progress_response = self.get(poll_url)
- percentage_complete = int(progress_response.get("progress", 0))
- task_state = progress_response.get("state")
- if task_state == "FAILED":
- log.error("PDF conversion not successful.")
+ percentage_complete = progress_response["percentageComplete"]
+ if task_timeout < time.monotonic():
+ raise Exception(
+ f"Timeout exceeded while waiting for task '{task_id}'."
+ f" Progress: {percentage_complete}%."
+ )
+
+ task_successful = progress_response["successful"]
+ task_finished = progress_response["finished"]
+ task_messages = [
+ msg["translation"] for msg in progress_response["messages"]
+ ]
+ if task_finished and not task_successful:
+ log.error("PDF conversion not successful. %r", task_messages)
return None
elif percentage_complete == 100:
running_task = False
- log.info(
- "Task completed - {task_state}".format(task_state=task_state)
- )
+ log.info("Task completed - successful")
log.debug("Extract task results to download PDF.")
- task_result_url = progress_response.get("result")
+ download_url = (
+ task_messages[0].split(' href="', 1)[1].split('"', 1)[0]
+ )
+
else:
log.info(
- "{percentage_complete}% - {task_state}".format(
+ "{percentage_complete}% complete".format(
percentage_complete=percentage_complete,
- task_state=task_state,
)
)
time.sleep(3)
@@ -114,8 +122,7 @@ class CustomConfluence(Confluence):
"Task successfully done, querying the task result for the download url"
)
# task result url starts with /wiki, remove it.
- task_content = self.get(task_result_url[5:], not_json_response=True)
- download_url = task_content.decode(encoding="utf-8", errors="strict")
+ download_url = download_url[5:]
log.debug("Successfully got the download url")
return download_url
except IndexError as e:
from atlassian-python-api.
Related Issues (20)
- need a function to set the test status in in test execution HOT 1
- Confluence Cloud Python API connection Timeouts
- Jira Software - rank API available? HOT 1
- [Jira] get_issue_changelog broken? HOT 2
- unexpected keyword argument 'paging_workaround' HOT 6
- Insight (Assets) class not correctly setting self.default_headers when cloud=True HOT 1
- [Confluence] Attachments - get_attachments_from_content HOT 1
- Bad Request for pullrequests with page params HOT 1
- bitbucket.project_list() only returns generators HOT 3
- Export page not working HOT 1
- Add label parameter to get_all_spaces method HOT 2
- pylint missing from requirements-dev.txt
- Edit issue not respect documentation
- Reading large confluence page
- export_page is giving 404 error
- Grammar and URL error on get_page_id
- black formatting in multiple versions of python HOT 3
- New release HOT 2
- confluence.add_user_to_group is wrong HOT 5
- [Jira] "Agile" methods don't use the “api_root” instance attribute, as most other methods do HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atlassian-python-api.