Create ticket in RT with python-rtkit having RESOU

2019-03-04 03:50发布

I'm new here. It's the same question as this one, but I didn't get answer so I post it again: how to create a ticket in rt using python-rtkit

I tried both CookieAuthenticator and BasicAuthenticator to create or read ticket but I still get the same error:

`RT/3.8.13 401 Credentials required` 

When I load the url directly in the browser: http://ticket.corp.kk.net/REST/1.0/ticket/214560?user=user&pass=pass, I DO get the ticket content in the browser.

I even tried the wget command to get one ticket content as below using cookie, and it works well:

  1. save manually the cookie value in the coookie.txt file:

    RT_SID_kk.net.80=5a1c1eb207c4e2ef5af726e98d751a08
    
  2. run this command:

    wget -O ticketContent.txt --keep-session-cookies --save-cookies cookies.txt 'http://ticket.corp.kk.net/REST/1.0/ticket/220680/show?format=l&user=user&pass=pass'
    

The ticket content is well registered in ticketContent.txt, which is showing using the cookie to authenticate is working.

But I still can not go through CookieAuthentication of rtkit in my python script.

I've been struggling on this problem for 2 days, I would deeply appreciate it if someone can help me out. Thank you.

标签: python rest rt
1条回答
干净又极端
2楼-- · 2019-03-04 04:27

I haven't found a solution for this problem , but I succeeded to use python Requests library to create a ticket in RT .

  1. install Requests lib. http://docs.python-requests.org/en/latest/user/install/#install
  2. create a new ticket in RT

    #!/usr/bin/python -u
    import requests,logging
    
    logging.basicConfig(level=logging.DEBUG)
    post_data = """
    id: ticket/new
    Queue: myqueue
    Subject: Test Ticket creation in RT with Python
    Text: Wow ticket is created :-D . 
    """
    payload = {'user': 'user', 'pass': 'password','content':post_data}
    ticket_creation_reusult = requests.post("http://ticket.corp.kk.net/rt3/REST/1.0/ticket/new", payload)
    
    logging.debug(ticket_creation_reusult.text)
    

The output is:

INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1):  ticket.corp.kk.net
DEBUG:requests.packages.urllib3.connectionpool:"POST /rt3/REST/1.0/ticket/new     HTTP/1.1" 200 None
DEBUG:root:RT/3.8.13 200 Ok
# Ticket 221173 created.

Hope this can help you , if you have the same problem as me . :-)

查看更多
登录 后发表回答