【发布时间】: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&pass=mypass"。并且可能指定它是 HTTP 还是 HTTPS。