如何使用python-rtkit在rt中创建票证 [英] how to create a ticket in rt using python-rtkit
问题描述
我遇到了一个简单的脚本,该脚本的唯一目的是在每次获得一张票时创建一张票证
I'm having trouble with a simple script whose only purpose is to create a single ticket and every time I get
401 Credentials Required
我从 https://github.com/z4r/python-rtkit. (出于安全原因,URL,用户名和密码已删除)
I took my code verbatim from https://github.com/z4r/python-rtkit. (URL, username and password are redacted for security reasons)
from rtkit.resource import RTResource
from rtkit.authenticators import BasicAuthenticator
from rtkit.errors import RTResourceError
from rtkit import set_logging
import logging
set_logging('debug')
logger = logging.getLogger('rtkit')
resource = RTResource('http://rt.example.com/REST/1.0/', 'user', 'pass', BasicAuthenticator)
#create a ticket
content = {
'content': {
'Queue': 'General - unassigned', #General - unassigned is the name of the desired queue
'Subject' : 'Test Ticket Python', #text to go into subject field
}
}
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)
这是我从中得到的输出
[DEBUG] POST ticket/new
[DEBUG] {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Accept': 'text/plain'}
[DEBUG] 'content=Queue: General - unassigned\nSubject: Test Ticket Python'
[INFO] POST
[INFO] http://rt.example.com/REST/1.0/ticket/new
[DEBUG] HTTP_STATUS: 200 OK
[DEBUG] 'RT/3.6.6 401 Credentials Required\n'
[DEBUG] RESOURCE_STATUS: 401 Credentials required
[INFO] []
[INFO] []
有人知道如何解决此问题吗?我只需要能够用python做票即可.因此,只要达到最终目标,其他不使用python-rtkit的方法也可以.
Anyone know how to fix this? I just need to be able to make tickets with python. So alternatively other methods of doing this that don't use python-rtkit is fine as long as it reaches the end goal.
从浏览器打开URL(登录后)会产生
Opening the url from my browser (after logging in) yields
RT/3.6.6 200 Ok
# Invalid object specificaiton: 'index.html'
id: index.html
(在登录之前)从浏览器中打开url
Opening the url from my browser (before logging in) yields
RT/3.6.6 401 Credentials Required
我对互联网方面的知识不是特别了解,所以我不确定如何查看返回的服务器标头.值得注意的是,我尝试过Cookie身份验证时没有得到更好的结果.
I'm not particularly knowledgeable about anything internet so I'm not sure how to look at the server's header that's returned. It's worth noting that I have tried Cookie Authentication without any better results.
@Zaroth的要求.我正在使用https.
@Zaroth's request. I'm using https.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://rt.example.com/REST/1.0/">here</a>.</p>
<hr>
<address>Apache/2.2.3 (Red Hat) Server at rt.hdms.com Port 80</address>
</body></html>
推荐答案
好的,我不知道为什么它第一次不起作用,但是我设法通过使用CookieAuthentication而不是BasicAuthentication使其立即起作用.
Alright, I don't know why it didn't work the first time but I've managed to get it working now by using CookieAuthentication instead of BasicAuthentication.
这篇关于如何使用python-rtkit在rt中创建票证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!