我正在尝试在Ubuntu 16.04中使用REST api从票证中获取一些内容,并且我很想使用下一个代码来获取该内容:
from rtkit.resource import RTResource
from rtkit.authenticators import QueryStringAuthenticator
from rtkit.errors import RTResourceError
from rtkit import set_logging
import logging
import re
set_logging('debug')
logger = logging.getLogger('rtkit')
resource = RTResource('http://ubuntu/rt/REST/1.0/', 'root', '**passwd**', QueryStringAuthenticator)
try:
response = resource.get(path='ticket/2')
myTicket = response.as_object() ## Returns an RtObj instance
except RTResourceError as e:
logger.error(e.response.status_int)
logger.error(e.response.status)
logger.error(e.response.parsed)
终端出现此错误:
File "LoginQuery.py", line 85, in <module>
myTicket = response.as_object() ## Returns an RtObj instance
AttributeError: 'RTResponse' object has no attribute 'as_object'
有人也有这个问题吗?并知道如何解决? 帮助:)
答案 0 :(得分:0)
根据软件包documentation,似乎读取响应的正确方法是使用response.parsed
:
try:
response = resource.get(path='ticket/1')
for r in response.parsed:
for t in r:
logger.info(t)
except RTResourceError as e:
logger.error(e.response.status_int)
logger.error(e.response.status)
logger.error(e.response.parsed)
答案 1 :(得分:0)
是的,但是我试图从内容中单独获取信息...几个小时后,我就这样了:
try:
response = resource.get(path='ticket/2')
Ticket = response.parsed
Criation = Ticket[0][12][1]
这可以让我了解创建日期的时间