当我尝试创建登录于Atlassian-confluence的登录名时,当我尝试通过传递用户名(email_id)和API令牌密码来创建对象时,出现错误“ NoneType”对象不可订阅。
我尝试使用具有相同用户电子邮件ID和密码的curl来访问URL,我得到如下有效响应:-
curl -v https://XXXXXXX.atlassian.net --user arun.kumar@something.com:xxxxxxxxxxxxxxxxxxxx
* Rebuilt URL to: https://projectcyclone.atlassian.net/
* Trying xx.xx.xx.xx...
* TCP_NODELAY set
* Connected to XXXXXXXX.atlassian.net (xx.xx.xx.xx) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Atlassian Network (easy handle 0x7f90af808400)
> GET / HTTP/2
> Host: XXXXXXXXXXX.atlassian.net
> Authorization: Basic YXJ1bi5rdW1hckB2aW9vaC5jb206VmYzYkRZUlRTR1I5ZHB6T3BqV3NENDNG
> User-Agent: curl/7.54.0
> Accept: */*
但是当我尝试使用凭据创建对象时,无法使用该对象调用方法。
confluence = Confluence(
url="https://XXXXXX.atlassian.net",
username="arun.kumar@something.com",
password="xxxxxxxxx")
try:
confluence.get_page_by_title("My space","MyPage")
except Exception as e:
print(e)
我收到以下错误:
“ NoneType”对象不可下标。
完整追溯:
回溯(最近通话最近):文件 “ /Users/k.arunkumar/confluence/py/confluence.py”,第26行,在 myconfluence confluence.get_page_by_title(“我的空间”,“我的页面”)文件 “ /Users/k.arunkumar/confluence/lib/python3.6/site-packages/atlassian/confluence.py”, 第128行,在get_page_by_title返回中(self.get(url,params = params)或 {})。get('results')[0] TypeError:“ NoneType”对象不是 可订阅的
答案 0 :(得分:0)
(self.get(url, params=params) or {}).get('results')[0]
行允许这种情况:
self.get(url, params=params)
返回None
,因为url
恰好是不存在的键(self.get(url, params=params) or {})
返回{}
(空的dict
)results
键(或任何其他键),因此{}.get('results')
是None
... None[0]
会导致您的错误。