HTTP status codes

86 views
Skip to first unread message

Carl

unread,
May 1, 2013, 10:13:05 AM5/1/13
to web...@googlegroups.com
Web2py supports a subset of HTTP status codes as listed here: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

The LinkedIn service I am using employs throttling and I'd like to throw a 429 Too Many Requests exception.

Can this status code, along with other missing codes, be added to web2py in gluon/http.py?


Leonel Câmara

unread,
May 1, 2013, 10:56:03 AM5/1/13
to web...@googlegroups.com
I guess you could add 429 to gluon.http definitions in your model and then use it, but I haven't tried it

Something like thin in your model

from gluon import http

http.defined_status[429] = 'Too Many Request'

And then in your controllers

raise HTTP(429)

Leonel Câmara

unread,
May 1, 2013, 10:57:41 AM5/1/13
to web...@googlegroups.com
Watch for the typos in the previous posts I must need more coffee or something


Quarta-feira, 1 de Maio de 2013 15:13:05 UTC+1, Carl escreveu:

Carl Roach

unread,
May 1, 2013, 10:57:36 AM5/1/13
to web...@googlegroups.com
thanks Leonel, I'm refactoring server calls at the mo, but I'll try that straight afterwards.


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/03sPc8GVBG0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Carl

unread,
May 1, 2013, 11:33:14 AM5/1/13
to web...@googlegroups.com
works sweetly.

from gluon import HTTP
from gluon.http import defined_status
if not(429 in defined_status):
    defined_status[429] = 'Too Many Requests'
raise HTTP(429, "Too Many Requests")



On Wednesday, 1 May 2013 15:57:36 UTC+1, Carl wrote:
thanks Leonel, I'm refactoring server calls at the mo, but I'll try that straight afterwards.
On 1 May 2013 15:56, Leonel Câmara wrote:
I guess you could add 429 to gluon.http definitions in your model and then use it, but I haven't tried it

Something like thin in your model

from gluon import http

http.defined_status[429] = 'Too Many Request'

And then in your controllers

raise HTTP(429)

Quarta-feira, 1 de Maio de 2013 15:13:05 UTC+1, Carl escreveu:
Web2py supports a subset of HTTP status codes as listed here: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

The LinkedIn service I am using employs throttling and I'd like to throw a 429 Too Many Requests exception.

Can this status code, along with other missing codes, be added to web2py in gluon/http.py?


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/03sPc8GVBG0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Anthony

unread,
May 1, 2013, 11:41:58 AM5/1/13
to web...@googlegroups.com
More simply, I think you can also just do this:

raise HTTP('429 Too Many Requests')

Anthony
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Carl Roach

unread,
May 1, 2013, 12:09:17 PM5/1/13
to web...@googlegroups.com
ah... the tyranny of /w

this works... HTTP('429 Too_Many_Requests')

In glucon/http.py HTTP regex_status isn't friendly to messages with whitespace (or hyphens)

Thanks for pointing me to this. One line simple line beats 5 simple lines! :)


 

Anthony

unread,
May 1, 2013, 12:48:12 PM5/1/13
to web...@googlegroups.com
Oops. Actually, I think this should be fixed -- I'll open an issue.

Anthony

Carl Roach

unread,
May 1, 2013, 12:51:10 PM5/1/13
to web...@googlegroups.com
thanks

Niphlod

unread,
May 1, 2013, 3:34:00 PM5/1/13
to web...@googlegroups.com
PS: having the missing one in gluon/http.py shouldn't be a performance-penalty.
Send a patch for the one missing but avoid being "too much off the standards" (like a "750 Didn't bother to compile it")

Anthony

unread,
May 1, 2013, 3:53:02 PM5/1/13
to web...@googlegroups.com
There's more than just one missing -- http://www.iana.org/assignments/http-status-codes/http-status-codes.xml lists 28 4xx codes alone. Perhaps we should add some of them explicitly, but we should also make it possible to raise other codes.

Anthony

Niphlod

unread,
May 1, 2013, 3:56:47 PM5/1/13
to web...@googlegroups.com
Yep, let me be clearer: +1 on giving the possibility to raise whatever you may find useful but if gluon/http.py misses some standard ones, we should include them.

Carl Roach

unread,
May 1, 2013, 3:58:29 PM5/1/13
to web...@googlegroups.com
The existing code makes it possible to raise any 3-digit status code.

raise HTTP('xxx Messsage_text')

though, see above post, spaces aren't allowed in Message_text in current regex.

Michele Comitini

unread,
May 1, 2013, 5:02:34 PM5/1/13
to web...@googlegroups.com
Shouldn't be:

HTTP(750, 'Make my day')

i.e. with the code as int and a description as str?


2013/5/1 Carl Roach <m...@carlroach.com>

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Carl Roach

unread,
May 1, 2013, 5:07:02 PM5/1/13
to web...@googlegroups.com

Two parameters for supported codes, but check http.py to() code and you'll see parsing present for the "compressed" parameter I described.

Michele Comitini

unread,
May 1, 2013, 5:21:05 PM5/1/13
to web...@googlegroups.com
you are right! that's horrible

I would put a new parameter

HTTP(status, body='', status_msg='')

inside the __init__:

if status_msg:
   defined_status[status] = status_msg



2013/5/1 Carl Roach <m...@carlroach.com>

Anthony

unread,
May 1, 2013, 5:55:29 PM5/1/13
to web...@googlegroups.com

HTTP(750, 'Make my day')

No, the second argument is the response body, not the status code description. Currently, there is no way to specify a separate text description for a numeric status code (though, as shown in other examples, you can have a string status that includes both the code and the description -- but at the moment, spaces are not allowed in the description).

Anthony 

Anthony

unread,
May 1, 2013, 6:01:07 PM5/1/13
to web...@googlegroups.com
Feel free to comment: https://code.google.com/p/web2py/issues/detail?id=1469&start=100


2013/5/1 Carl Roach <m...@carlroach.com>


2013/5/1 Carl Roach <m...@carlroach.com>
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

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

--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/03sPc8GVBG0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages