4

I am attempting to create a ticket in RT using python-rtkit, it gives a 200 OK and returns the information for an empty ticket that does not actually get created in RT, additionally I tried straight up using the requests module, and that had the same result as well.

My code attempting to use the requests module

post_data = """
id: ticket/new
Queue: myqueue
Subject: Test Ticket creation in RT with Python
Text: Wow ticket is created :-D . 
"""
payload = {'content':post_data}
ticket_creation_reusult = requests.post("http://rt.domain.com/REST/1.0/ticket/new"+"user="+user+"&pass="+pas, payload)

My code attempting to use the requests python-rtkit,

content = {
    'content': {
        'Queue': 1,#'', 2
        'Subject': 'New Ticket',
        'Text': 'My useless\ntext on\nthree lines.',
    }
}
try:
    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)

The output:

[DEBUG] POST ticket/new
[DEBUG] {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8','Accept': 'text/plain'}
[DEBUG] 'content=Queue: 1\nText:My+useless%0A+text+on%0A+three+lines.\nSubject: New Ticket'
[INFO] POST
[INFO] http://nocrt.domain.com/REST/1.0/ticket/new
[DEBUG] HTTP_STATUS: 200 OK
[DEBUG] 'RT/4.2.9 200 Ok\n\n# Required: id, Queue\n\nid: ticket/new\nQueue:General\nRequestor: svc_nocrt\nSubject: \nCc:\nAdminCc:\nOwner: \nStatus:new\nPriority: 5\nInitialPriority:5\nFinalPriority: 1\nTimeEstimated: 0\nStarts: 2015-07-2014:20:07\nDue: 2015-07-27 14:20:07\nAttachment: \nText: \n\n'
[DEBUG] RESOURCE_STATUS: 200 Ok
[INFO] [[('id', 'ticket/new'), ('Queue', 'General'), ('Requestor','svc_nocrt'), ('Subject', ''), ('Cc', ''), ('AdminCc', ''),('Owner', ''), ('Status', 'new'), ('Priority', '5'), ('InitialPriority', '5'),('FinalPriority', '1'), ('TimeEstimated', '0'), ('Starts', '2015-07-2014:20:07'), ('Due', '2015-07-27 14:20:07'), ('Attachment', ''), ('Text', '')]]
[INFO] [[('id', 'ticket/new'), ('Queue', 'General'), ('Requestor','svc_nocrt'), ('Subject', ''), ('Cc', ''), ('AdminCc', ''),('Owner', ''), ('Status', 'new'), ('Priority', '5'), ('InitialPriority', '5'),('FinalPriority', '1'),('TimeEstimated', '0'), ('Starts', '2015-07-2014:20:07'),('Due', '2015-07-27 14:20:07'), ('Attachment', ''), ('Text', '')]]

It looks like it's creating an empty ticket; but nothing shows up in the web interface, these are the examples for python-rtkit and another I found from here but that gives the same result

Community
  • 1
  • 1
Mark Omo
  • 898
  • 2
  • 12
  • 26
  • As an aside, it is 'wrong' to `POST` to a URI such as `.../new`. The method `POST` already implies the action you want is to create a new 'thing'. As such, you should just `POST /ticket`. – thecoshman Jul 23 '15 at 09:31

1 Answers1

0

Contrary to your expectation, that is actually an error message.

As you can see here you are going through the path (lines 92-105) which are actually a default error path when it cannot find any fields to create a ticket. It only actually creates the ticket if you go through the other branch below this (lines 128-184).

The problem appears to be that your server is not actually picking up your content field at all. Your rtkit client-side code looks like it's come straight from the rtkit docs and so should be correct. I'd therefore have to guess that there is something wrong with the construction of your RTResource object or something filtering your request between your client and server.

I suspect that it might be the use of the multiline text. Perhaps the lines have not been correctly encoded and so your server is rejecting the posted data? You could try proving that by making it a simpler piece of text instead.

I'd also look at the requests version you submitted, but I'm afradi I've run out of time.

Peter Brittain
  • 13,489
  • 3
  • 41
  • 57