2014-10-03 33 views
0

我是新來的。這是因爲這一個同樣的問題,但我沒有得到回答,所以我再重新發布:how to create a ticket in rt using python-rtkit使用具有RESOURCE_STATUS的python-rtkit創建RT票證:401需要憑證

我都嘗試CookieAuthenticatorBasicAuthenticator來創建或讀取票,但我仍然得到了同樣的錯誤:

`RT/3.8.13 401 Credentials required` 

當我直接在瀏覽器中加載url時:http://ticket.corp.kk.net/REST/1.0/ticket/214560?user=user&pass=pass,我會在瀏覽器中獲取票據內容。

我甚至試過wget命令來獲得一頁的內容如下使用cookie,並且它工作得很好:

  1. 手動保存在coookie.txt文件中的cookie值:

    RT_SID_kk.net.80=5a1c1eb207c4e2ef5af726e98d751a08 
    
  2. 運行此命令:

    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' 
    

門票內容已在ticketContent.txt中很好地註冊,這表明使用cookie進行身份驗證正在工作。

但我仍然不能在我的python腳本中通過rtkit的CookieAuthentication

我一直在這個問題上掙扎了兩天,如果有人能幫助我,我會深表謝意。謝謝。

+0

可能重複[如何使用python-rtkit在rt中創建票證](http://stackoverflow.com/questions/17890098/how-to-create-a-ticket-in-rt-using -python-rtkit) – ElGavilan 2014-11-07 15:01:44

回答

0

我還沒有找到這個問題的解決方案,但我成功地使用python請求庫在RT中創建一張票。

  1. install請求lib。 http://docs.python-requests.org/en/latest/user/install/#install
  2. 在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) 
    

輸出是創建一個新的票:

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. 

希望這可以幫助你,如果你有同樣的問題我。 :-)