python - rtkit 给出 ValueError : need more than 1 value to unpack

标签 python rest rt

我有一个使用 python-rtkit 的 python 脚本来尝试在请求跟踪器 (RT) 中创建票证,并且我可以让它与队列、主题和状态字段一起使用。但我尝试将“设备或区域”字段添加到我的有效负载中,但出现错误:

Traceback (most recent call last):
  File "resttest.py", line 23, in <module>
    response = resource.post(path='ticket/new', payload=content)
  File "build\bdist.win32\egg\rtkit\resource.py", line 29, in post
  File "build\bdist.win32\egg\rtkit\resource.py", line 49, in request
  File "build\bdist.win32\egg\rtkit\resource.py", line 104, in __init__
  File "build\bdist.win32\egg\rtkit\parser.py", line 49, in parse
  File "build\bdist.win32\egg\rtkit\parser.py", line 79, in decode_comment
ValueError: need more than 1 value to unpack

这是我的代码

from rtkit.resource import RTResource
from rtkit.authenticators import BasicAuthenticator, CookieAuthenticator
from rtkit.errors import RTResourceError

from rtkit import set_logging
import logging
set_logging('debug')
logger = logging.getLogger('rtkit')

resource = RTResource(rt_url, rt_user, rt_pass, CookieAuthenticator)

#create a ticket
content = {
    'content': {
        'Queue': 'General - unassigned',
        'Subject' : 'Test Ticket Python 2',
        'Status' : 'open',
        'Device or Area' : 'Backups',
        }
    }
try:
    print content
    response = resource.post(path='ticket/new', payload=content,)
    logger.info(response.parsed)
except RTResourceError as e:
    logger.error(e.response.status_int)
    logger.error(e.response.status)
    logger.error(e.response.parsed)

有谁知道这个错误的含义以及导致它的原因(以便我可以修复它)?

编辑:我认为值得注意的是,如果我只是删除新票证的“设备或区域”条目,它就可以正常工作。添加该字段(或任何其他与此相关的字段)会破坏代码。

编辑:@sihrc 这是在没有嵌套字典结构的情况下运行的输出

{'Queue': 'General - unassigned', 'Status': 'open', 'Device or Area': 'Backups',
 'Subject': 'Test Ticket Python 2'}
[DEBUG] POST ticket/new
[DEBUG] {'Content-Length': '601', 'Content-Type': 'multipart/form-data; boundary
=xXXxXXyYYzzz', 'Accept': 'text/plain'}
[DEBUG] '--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="Queue"\r\nConte
nt-Type: text/plain; charset=utf-8\r\nContent-Length: 24\r\n\r\nGeneral%20-%20un
assigned\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="Status"\r\nC
ontent-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\nopen\r\n--xXX
xXXyYYzzz\r\nContent-Disposition: form-data; name="Device%20or%20Area"\r\nConten
t-Type: text/plain; charset=utf-8\r\nContent-Length: 7\r\n\r\nBackups\r\n--xXXxX
XyYYzzz\r\nContent-Disposition: form-data; name="Subject"\r\nContent-Type: text/
plain; charset=utf-8\r\nContent-Length: 26\r\n\r\nTest%20Ticket%20Python%202\r\n
--xXXxXXyYYzzz--\r\n'
[INFO] POST
[INFO] https://rt.redactedurl.com/REST/1.0/ticket/new
[DEBUG] HTTP_STATUS: 200 OK
[DEBUG] 'RT/3.6.6 200 Ok\n\n# Required: id, Queue\n\nid: ticket/new\nQueue: \nRe
questor: jgreen\nSubject: \nCc:\nAdminCc:\nOwner: \nStatus: new\nPriority: \nIni
tialPriority: \nFinalPriority: \nTimeEstimated: 0\nStarts: 2013-07-29 16:19:19\n
Due: 2013-07-29 16:19:19\nText: \n\n'
[DEBUG] RESOURCE_STATUS: 200 Ok
[INFO] [[('id', 'ticket/new'), ('Queue', ''), ('Requestor', 'jgreen'), ('Subject
', ''), ('Cc', ''), ('AdminCc', ''), ('Owner', ''), ('Status', 'new'), ('Priorit
y', ''), ('InitialPriority', ''), ('FinalPriority', ''), ('TimeEstimated', '0'),
 ('Starts', '2013-07-29 16:19:19'), ('Due', '2013-07-29 16:19:19'), ('Text', '')
]]
[INFO] [[('id', 'ticket/new'), ('Queue', ''), ('Requestor', 'jgreen'), ('Subject
', ''), ('Cc', ''), ('AdminCc', ''), ('Owner', ''), ('Status', 'new'), ('Priorit
y', ''), ('InitialPriority', ''), ('FinalPriority', ''), ('TimeEstimated', '0'),
 ('Starts', '2013-07-29 16:19:19'), ('Due', '2013-07-29 16:19:19'), ('Text', '')
]]

此后不会创建新票证。

最佳答案

“设备或区域”看起来是自定义字段,因此您需要在其前面添加“CF-”以匹配 RT REST 接口(interface)对自定义字段的期望。您可以看到底层的REST语法on the community wiki here .

关于python - rtkit 给出 ValueError : need more than 1 value to unpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17928643/

相关文章:

android - 哪个是适用于 Android 的最佳 SIP 兼容编解码器类型

java - 无法将附件添加到新 RT 票证中

java - 基于 Http 调用的 RESTFul Web 服务类型框架

iphone - 基于 SAML 2.0 的 iPhone 应用程序身份验证

Python图形工具通过索引有效地访问顶点属性

python paramiko错误 "AttributeError: ' NoneType'对象没有属性 'open_session'“

mysql - 在 MySQL 中旋转 - 一次只能在一行上工作?

real-time - Sphinx 重新索引 RT 索引

python - 根据条件删除numpy数组中的行

Python - 为什么在类里面使用 "self"?