1

I have a python script using python-rtkit to try and create tickets in Request Tracker (RT) and I can get it to work with the Queue, Subject, and Status fields. But I tried to add the 'Device or Area' field into my payload and it gives the error:

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

Here's my code

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)

Does anyone know what this error means and what's causing it (so that I can fix it)?

EDIT: I believe that it's worth noting that if I just remove the 'Device or Area' entry for the new ticket that it works fine. It's the adding of that field (or just about any other field for that matter) that breaks the code.

EDIT: @sihrc Here's the output from running without the nested dict structure

{'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', '')
]]

After this no new ticket is created.

4

2 回答 2

1

“设备或区域”看起来是一个自定义字段,因此您需要在其前面添加一个“CF-”以匹配 RT REST 接口对自定义字段的期望。您可以在此处的社区 wiki 上查看底层 REST 语法。

于 2013-07-30T18:24:02.793 回答
0

我不知道错误的确切含义,但我能够通过更改设备或区域的密钥来修复它,因为显然它在页面中标记的内容和它在数据库中存储的内容是不同的。

于 2013-07-29T16:34:49.650 回答