【问题标题】:how to create a ticket in rt using python-rtkit如何使用 python-rtkit 在 rt 中创建票证
【发布时间】:2013-07-26 20:05:06
【问题描述】:

我在使用一个简单的脚本时遇到问题,它的唯一目的是创建一个单张票,并且每次我得到 ​​p>

401 Credentials Required

我从https://github.com/z4r/python-rtkit 逐字获取了我的代码。 (出于安全原因,URL、用户名和密码已编辑)

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 的方法也可以。

编辑: 从我的浏览器打开网址(登录后)产生

RT/3.6.6 200 Ok

# Invalid object specificaiton: 'index.html'

id: index.html

从我的浏览器打开网址(在登录之前)产生

RT/3.6.6 401 Credentials Required

我对任何互联网都不是特别了解,所以我不确定如何查看返回的服务器标头。值得注意的是,我尝试了 Cookie 身份验证,但没有任何更好的结果。

编辑: @Zaroth 的请求。我正在使用 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>

【问题讨论】:

  • 您能否粘贴以下命令的输出:curl "http://rt.example.com/REST/1.0/" -d "user=myuser&amp;pass=mypass"。并且可能指定它是 HTTP 还是 HTTPS。

标签: python rest rt


【解决方案1】:

好吧,我不知道为什么它第一次没有工作,但我现在通过使用 CookieAuthentication 而不是 BasicAuthentication 设法让它工作。

【讨论】:

    【解决方案2】:

    您必须为您的 RT Web 服务使用正确的 URL。

    我假设 URL http://rt.example.com/REST/1.0/ 没有指向您正在运行的 RT 实例?

    或者您是否已将 rt.example.com 添加到您的 hosts 文件或类似文件中?

    您的 RT 实例在哪个主机/端口上运行?

    【讨论】:

    • 这是一个编辑过的网址。出于安全原因,我无法提供我公司的实际 URL 或用户/通行证。很抱歉有任何混淆。
    • 好的,那么你的网址是https://servername/REST/1.0/... 吗?如果您尝试从浏览器打开 URL,会发生什么情况?您可以尝试一下并查看来自服务器的响应标头吗?也许您的设置使用了另一种身份验证方案(即不是基本身份验证)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多