![](/img/trans.png)
[英]How get context Confluence using atlassian-python-api?
[英]atlassian-python-api exception by using confluence.delete_attachment()
我嘗試使用 confluence.delete_attachment(page_id, filename, version) 從站點中刪除所有附件,但它總是拋出相同的異常: requests.exceptions.HTTPError: 401 Client Error: Authorization required for url:
我目前正在刪除附件,如下所示:
from atlassian import Confluence
confluence_url = 'https://xxx/confluence/'
confluence_usr = os.environ.get('CONFLUENCE_CREDS_USR')
confluence_psw = os.environ.get('CONFLUENCE_CREDS_PSW')
confluence = Confluence(url=confluence_url, username=confluence_usr, password=confluence_psw)
# Check site response, if site not reachable, check 5 times every 5 sec
response = resilient_confluence_http_get_request(f'{confluence_url}rest/api/content/{page_ids[csv_file]}')
# Check site response, if site not reachable, check 5 times every 5 sec
attachment = confluence.get_attachments_from_content(page_ids[csv_file])
print(f"attachment type: {type(attachment)}")
print(f"attachment content:\n {attachment}\n\n")
att_to_del = []
indices = 0
for i in attachment['results']:
print(f"id type: {type(attachment['results'][indices]['id'])}")
att_to_del.append(attachment['results'][indices]['id'])
indices += 1
print(f"delete attachments with id's {att_to_del}")
for id_to_delete in att_to_del:
response = requests.delete(f'https://xxx/confluence/rest/api/content/{id_to_delete}',
auth=(confluence_usr, confluence_psw))
刪除 function 是唯一不起作用的。 我究竟做錯了什么?
在這里我嘗試使用 confluence.delete_attachment(...) 刪除:
def response_wait_repeat():
attachments = confluence.get_attachments_from_content('my_site_id')
print(attachments)
confluence.delete_attachment('my_site_id', 'my_filename', version=None)
我假設您使用的是atlassian-python-api
作為 pypi 文檔中的示例,您首先需要創建與 confluence 的連接:
from atlassian import Confluence
confluence = Confluence(
url='http://localhost:8090',
username='admin',
password='admin')
status = confluence.create_page(
space='DEMO',
title='This is the title',
body='This is the body. You can use <strong>HTML tags</strong>!')
print(status)
如果您仍然收到此錯誤( 401 Authorization Required
),我會在融合中手動檢查您是否有權執行這些操作。
可能是這種情況,因為您說您不能執行的唯一操作是刪除。
否則我會聯系 confluence 管理員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.