我正在尝试创建一个Python脚本,该脚本采用confluence.py中的部分代码(https://github.com/atlassian-api/atlassian-python-api/blob/master/atlassian/confluence.py#L105 )
具体来说,我试图在脚本中从头开始重新创建函数“page_exists”,但总的来说,我想从头开始从页面创建我自己的代码。
但是,我遇到了一些错误。 这样我们就出现了变量 self '未定义' 的错误:
response = self.get(url, params=params)
您认为重新创建此功能的最佳方法是什么?我的目标是将来能够根据自己的需求定制此类融合功能。
在我的代码下面:
from atlassian import Confluence
f = open('log.txt','w')
print('file open', file=f) # Python 3.x
confluence = Confluence(
url='https://site_name.atlassian.net',
username='email',
password='Token_API',
cloud=True)
print('connetion established', file=f) # Python 3.x
space='TEAM'
title="new page"
print('variables defined', file=f) # Python 3.x
url = "rest/api/content"
params = {}
if space is not None:
params["spaceKey"] = str(space)
if title is not None:
params["title"] = str(title)
if type is not None:
params["type"] = str(type)
try:
response = self.get(url, params=params)
except HTTPError as e:
if e.response.status_code == 404:
raise ApiPermissionError(
"The calling user does not have permission to view the content",
reason=e,
)
raise
print('bgin the if', file=f) # Python 3.x
if response.get("results"):
print('page exists', file=f) # Python 3.x
else:
print('page does not exist', file=f) # Python 3.x
我已经能够通过以下方式取得积极成果:
from atlassian import Confluence
confluence = Confluence(
url='https://site_name.atlassian.net',
username='email',
password='API_token',
cloud=True)
f = open('log.txt','w')
print('connetion established', file=f) # Python 3.x
space='TEAM'
title="new page"
print('variables defined', file=f) # Python 3.x
url = "rest/api/content"
params = {}
if space is not None:
params["spaceKey"] = str(space)
if title is not None:
params["title"] = str(title)
if type is not None:
params["tipe"] = str(type)
response = confluence.get(url, params=params)
if response.get("results"):
print('page exists', file=f) # Python 3.x
else:
print('page does not exist', file=f) # Python 3.x