Create ticket in RT with python-rtkit having RESOURCE_STATUS: 401 Credentials required

点点圈 提交于 2019-12-02 16:31:46

问题


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.


回答1:


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 . :-)



来源:https://stackoverflow.com/questions/26186065/create-ticket-in-rt-with-python-rtkit-having-resource-status-401-credentials-re

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!