@simple_service('GET', TEST_SERVICE_ID, 'testrdf', 'application/xml+rdf')
def testrdf():
response.code = "404 Not Found"
It has an ambiguous behaviour. I don't know if it is ok or if it is a bug:
$ curl http://localhost:8880/testrdf -I
HTTP/1.1 404 Not Found
Server: Akara/2.0
Date: Tue, 07 Jun 2011 15:14:55 GMT
Content-Type: application/xml+rdf
Connection: close
$ curl http://localhost:8880/testrdf
Internal Server Error
The error at error.log:
Jun 07 17:14:58 akara[3759]: [stderr]
File "/home/lm/entorno_iaaa/lib/python2.7/site-packages/Akara-2.0a3-py2.7.egg/akara/multiprocess_http.py",
line 98, in _child
Jun 07 17:14:58 akara[3759]: [stderr]
preforkserver.PreforkServer._child(self, sock, parent)
Jun 07 17:14:58 akara[3759]: [stderr]
File "/home/lm/entorno_iaaa/lib/python2.7/site-packages/Akara-2.0a3-py2.7.egg/akara/thirdparty/preforkserver.py",
line 405, in _child
Jun 07 17:14:58 akara[3759]: [stderr]
self._jobClass(clientSock, addr, *self._jobArgs).run()
Jun 07 17:14:58 akara[3759]: [stderr]
File
"/home/lm/entorno_iaaa/lib/python2.7/site-packages/Akara-2.0a3-py2.7.egg/akara/multiprocess_http.py",
line 119, in run
Jun 07 17:14:58 akara[3759]: [stderr]
self.handler = AkaraWSGIHandler(self._sock, self._addr,
handler)
Jun 07 17:14:58 akara[3759]: [stderr]
File "/usr/lib/python2.7/SocketServer.py", line 639,
in __init__
Jun 07 17:14:58 akara[3759]: [stderr]
self.handle()
Jun 07 17:14:58 akara[3759]: [stderr]
File
"/home/lm/entorno_iaaa/lib/python2.7/site-packages/Akara-2.0a3-py2.7.egg/akara/thirdparty/httpserver.py",
line 474, in handle
Jun 07 17:14:58 akara[3759]: [stderr]
BaseHTTPRequestHandler.handle(self)
Jun 07 17:14:58 akara[3759]: [stderr]
File "/usr/lib/python2.7/BaseHTTPServer.py",
line 343, in handle
Jun 07 17:14:58 akara[3759]: [stderr]
self.handle_one_request()
Jun 07 17:14:58 akara[3759]: [stderr]
File
"/home/lm/entorno_iaaa/lib/python2.7/site-packages/Akara-2.0a3-py2.7.egg/akara/thirdparty/httpserver.py",
line 469, in handle_one_request
Jun 07 17:14:58 akara[3759]: [stderr]
self.wsgi_execute()
Jun 07 17:14:58 akara[3759]: [stderr]
File
"/home/lm/entorno_iaaa/lib/python2.7/site-packages/Akara-2.0a3-py2.7.egg/akara/thirdparty/httpserver.py",
line 306, in wsgi_execute
Jun 07 17:14:58 akara[3759]: [stderr]
for chunk in result:
Jun 07 17:14:58 akara[3759]: [stderr]
TypeError: 'NoneType' object is not
iterable
Saludos,
-- luismiguel
l
On Tue, Jun 7, 2011 at 11:20 AM, Luis Miguel Morillas
<mori...@gmail.com> wrote:
> When a simple_service returns a non text content-type and there is not
> a return because of a 404:
>
> @simple_service('GET', TEST_SERVICE_ID, 'testrdf', 'application/xml+rdf')
> def testrdf():
> response.code = "404 Not Found"
You still need the return(), as the traceback suggests. If you need
to use a different content-type in an error response than is specified
in the simple_service declaration, just use akara.response. FWIW, I've
used this function in conjunction with simple_service (as well as
those using method_dispatcher);
def HttpResponse(code,text,ctype,headers):
response.code=code
response.headers.extend(headers or [])
response.headers.append(('Content-Type',ctype))
return(text)
then to return an HTTP error, I use;
return HttpResponse(500,'Bad JSON input','text/plain')
I've used "headers" for providing, for example, the Location header on
a 201 response.
Mark.