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
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)
Here's the output I get from this
[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] []
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.
EDIT: Opening the url from my browser (after logging in) yields
RT/3.6.6 200 Ok
# Invalid object specificaiton: 'index.html'
id: index.html
Opening the url from my browser (before logging in) yields
RT/3.6.6 401 Credentials Required
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.
EDIT: @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>
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.