Discussion:
[bottlepy] How to use Response/Request objects?
Tristan Kohl
2015-07-02 19:39:54 UTC
Permalink
Hello guys,

I am toying around with bottle for quite a while now (managed to get Bottle
subapps running, etc.) and made myself some great tools but up until now I
am not capable to use the Response and Request objects properly.
I think the blame is on me, but even if I return a Response object which is
instantiated with i.e. status code 400, Bottle returns status code 200.


My code is something like this:
####
from bottle import Response

if SOME_CONDITION_LEADING_TO_PROBLEM:
res = Response(body=SOME_ERROR_DESC, status=400, header=xyz)
return res
####

Now I start a test run with curl, which should raise the condition above:
####
curl -i -H "Content-Type: application/json" -X GET -d
'{"func":"get","data":"xyz", "args":["xyz", "xyz"]}' http://127.0.0.1:12000/
####

But I always get something like this:
####
HTTP/1.0 200 OK <---- This is not, what I want
Date: Thu, 02 Jul 2015 19:22:00 GMT
Server: WSGIServer/0.2 CPython/3.4.3
blablabla...
####


I am pretty sure there is something I am doing wrong but I do not have a
clue what that might be. Similar problems rise with the Request object
which I don't know how to use :(((
Help is very much appreciated!


Cheers,
Tristan


@Marcel: awesome peace of software :)
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Helton Alves
2015-07-02 21:23:56 UTC
Permalink
Marcel, how are you?
so, can you put your code in http://pastebin.com/ for us see your code?

that the force be with you! o/
Post by Tristan Kohl
Hello guys,
I am toying around with bottle for quite a while now (managed to get
Bottle subapps running, etc.) and made myself some great tools but up until
now I am not capable to use the Response and Request objects properly.
I think the blame is on me, but even if I return a Response object which
is instantiated with i.e. status code 400, Bottle returns status code 200.
####
from bottle import Response
res = Response(body=SOME_ERROR_DESC, status=400, header=xyz)
return res
####
####
curl -i -H "Content-Type: application/json" -X GET -d
'{"func":"get","data":"xyz", "args":["xyz", "xyz"]}'
http://127.0.0.1:12000/
####
####
HTTP/1.0 200 OK <---- This is not, what I want
Date: Thu, 02 Jul 2015 19:22:00 GMT
Server: WSGIServer/0.2 CPython/3.4.3
blablabla...
####
I am pretty sure there is something I am doing wrong but I do not have a
clue what that might be. Similar problems rise with the Request object
which I don't know how to use :(((
Help is very much appreciated!
Cheers,
Tristan
@Marcel: awesome peace of software :)
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tristan Kohl
2015-07-03 07:53:28 UTC
Permalink
As of today I just use the default "request"/"response":

# Here I want to use new Request/Response objects in place of the default
request.

from bottle import request, response

def validate(self):
"""
Validate header and content of incomming request.
"""
if request.get_header("Content-Type") == "application/json":
if "func" in request.json and "data" in request.json:
return True
else:
response.status = "400 Bad Request" # something like res =
Response(body=DESC, status=400)
else:
response.status = "415 Unsupported Media Type"
...
return response # return res
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...