that is an unfortunate misnaming in the datetime module

the datetime module holds:
- datetime
- timedelta
- tzinfo
- time
as "submodules".

web2py uses 

import datetime

and then it uses 
datetime.datetime.now()

while your code probably does

from datetime import datetime

and then uses 
datetime.now()



in that case, the datetime "submodule" that you're importing "overwrites" 
the "root" one.

just rewrite your module imports using

import datetime

or 

from datetime import datetime as dt

and then use

dt.now()



to avoid that error.

BTW: use request.now instead of datetime.datetime.now() if you want to 
avoid the whole misbehaviour 

On Thursday, February 20, 2014 5:39:00 PM UTC+1, Manuele wrote:
>
> Hi! 
> trying to schedule a task with the scheduler in this way: 
>
> scheduler.queue_task('test_networking', pvars=dict(body=oldbody), 
>             # do un minuto per riavviare l'interfaccia 
>             start_time = datetime.now() + timedelta(minutes=1), 
>             # periodo di test (default 10 min) 
>             stop_time = datetime.now() + timedelta(minutes=testperiod), 
>             # test ogni 120 secondi 
>             period = 120, 
>             # illimitato per il periodo impostato 
>             repeats = 0 
>         ) 
>
> I get this traceback: 
>
> Traceback (most recent call last): 
>   File "/home/paytor/web2py.mini/gluon/scheduler.py", line 238, in 
> executor 
>     result = dumps(_function(*args, **vars)) 
>   File "applications/paytorpanel/models/scheduler.py", line 61, in 
> update_net_interface 
>     repeats = 0 
>   File "/home/paytor/web2py.mini/gluon/scheduler.py", line 983, in 
> queue_task 
>     **kwargs) 
>   File "/home/paytor/web2py.mini/gluon/dal.py", line 9020, in 
> validate_and_insert 
>     response.id = self.insert(**new_fields) 
>   File "/home/paytor/web2py.mini/gluon/dal.py", line 9003, in insert 
>     ret =  self._db._adapter.insert(self, self._listify(fields)) 
>   File "/home/paytor/web2py.mini/gluon/dal.py", line 1304, in insert 
>     query = self._insert(table,fields) 
>   File "/home/paytor/web2py.mini/gluon/dal.py", line 1294, in _insert 
>     values = ','.join(self.expand(v, f.type) for f, v in fields) 
>   File "/home/paytor/web2py.mini/gluon/dal.py", line 1294, in <genexpr> 
>     values = ','.join(self.expand(v, f.type) for f, v in fields) 
>   File "/home/paytor/web2py.mini/gluon/dal.py", line 1503, in expand 
>     return str(self.represent(expression,field_type)) 
>   File "/home/paytor/web2py.mini/gluon/dal.py", line 1921, in represent 
>     obj = obj() 
>   File "/home/paytor/web2py.mini/gluon/scheduler.py", line 470, in now 
>     return self.utc_time and datetime.datetime.utcnow() or 
> datetime.datetime.now() 
> AttributeError: type object 'datetime.datetime' has no attribute 
> 'datetime' 
>
> could it be a bug in scheduler or I'm doing something wrong? 
>
> I'm using this version of web2py: Version 
> 2.8.2-stable+timestamp.2013.11.28.13.54.07 
>
> Thanks a lot 
>
> Cheers 
>
>     Manuele 
>

-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to