开发者

Python: ServiceDesk PLus Servlet API

I am new to programming in Python and am writing a script for my company. We use ServiceDesk Plus which uses Servlet API. I want to write a script that will auto create/close tickets upon alarms from Solarwinds.

I cannot figure out the syntax for auto creating a ticket using the servlet API in python. Here is what I have (that does not work):

url = 'http://localhost:6970/servlets/RequestServlet/' 
params = urllib.urlencode({
  'operation': 'AddRequest',
})
response = urllib2.urlopen(url, params).read()

Any help would be very appreciated.

EDIT:

I tried what James recommended with no luck. here is what my script looks like using that advice.

import urllib
import urllib2

url = 'http://localhost:6970/servlets/RequestServlet/' 
params = urllib.urlen开发者_JS百科code({
    'operation': 'AddRequest',
    'username': 'lou',
    'password': 'lou',
    'requester': 'Sean Adams',
    'subject': 'Test Script Req',
    'description': 'TESTING!!!!!!',
    })
request = urllib2.Request('http://localhost:6970/servlets/RequestServlet/' ,params)
response = urllib2.urlopen(request) 

The errors:

C:\Users\lou\Desktop>python helpdesk2.py
Traceback (most recent call last):
  File "helpdesk2.py", line 24, in <module>
    response = urllib2.urlopen(request)
  File "C:\Python27\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 400, in open
    response = meth(req, response)
  File "C:\Python27\lib\urllib2.py", line 513, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python27\lib\urllib2.py", line 438, in error
    return self._call_chain(*args)
  File "C:\Python27\lib\urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 521, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: /servlets/RequestServlet/


You thus got the following error:

urllib2.HTTPError: HTTP Error 404: /servlets/RequestServlet/

A HTTP 404 error simply means that the requested resource doesn't exist. You would have gotten exactly the same error when opening the page by http://localhost:6970/servlets/RequestServlet/ in your favourite webbrowser.

There are many possible causes for this. For example,

  • Is the URL really correct? It's case sensitive!
  • Is the webapp properly deployed? Read server startup logs.
  • Is the servlet properly initialized? Read webapp startup logs.
  • Is the servlet properly mapped on that URL? Given the trailing slash in URL, the servlet mapping URL pattern should be /RequestServlet/* assuming that /servlets is the webapp context path, or if it is actually mapped on an URL pattern of /RequestServlet then you should be using an URL of http://localhost:6970/servlets/RequestServlet without the trailing slash.


Maybe try creating a request first, then opening the request?

    params = urllib.urlencode({
  'operation': 'AddRequest',
     })
    request = urllib2.Request('http://localhost:6970/servlets/RequestServlet/' ,params)
    response = urllib2.urlopen(request)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜