我在使用一个简单的脚本时遇到了问题,它的唯一目的是创建一张票,每次我得到
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>