How to get host and scheme from a scheduled task?

48 views
Skip to first unread message

Lisandro

unread,
Mar 1, 2015, 1:40:55 PM3/1/15
to web...@googlegroups.com
From the book (scheduler documentation) [1]: 
"Tasks differ from a controller action because they are not associated with an HTTP request and therefore there is no request.env"

I have several method fields that generate urls using URL() function with args scheme=True and host=True, but when those methods are called from a scheduled task, the "host" in the final url is 127.0.0.1, and I need it to be the main domain. 

So, is it possible to get host and scheme from a scheduled task given that there is no http request? Thanks in advance.


Niphlod

unread,
Mar 1, 2015, 2:37:49 PM3/1/15
to web...@googlegroups.com
uhm....... the host is different from the hostname and from the "domain". Usually, the pretty thing about the request environment is that there is a "Host" header sent by client that indicates which "domain" it has been accessed. This makes your application unaware that is running on a particular domain, whilst keep it working without issues.
Since the scheduler can run on any hostname (also in ones that don't usually have a webserver), we can't known what hostname may have been requested, and that host header is never coming in to signal what is the proper hostname to use.

tl;dr:  use URL(......., host='www.domain.com') instead of URL(...., host=True)

 

Lisandro Rostagno

unread,
Mar 1, 2015, 2:46:28 PM3/1/15
to web...@googlegroups.com
I understand. thank you very much for the answer.
I guess I will add a global variable to set the main domain and use it in those cases.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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/G34QiEhOi0s/unsubscribe.
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/d/optout.

Reply all
Reply to author
Forward
0 new messages