One more observation: If I am using APScheduler instead of web2py Scheduler , everything works fine and I am able to see the post in the mail, so not sure why module requests is not recognized in case of web2py Scheduler.
Below are the code using APScheduler: from apscheduler.scheduler import Scheduler sched = Scheduler() sched.start() @sched.interval_schedule(minutes=1) def send_mail(): message = 'Hello' post_message(message) from mailgun import * import requests def post_message(testmessage): r = requests.post(("https://api.mailgun.net/v2/amit.mailgun.org/" "messages"), auth=("api", "key-3k7c-lqsdfssssnphzid4rbmnr9vp913y9q94"), data={ "from": "Excited User <a...@amit.mailgun.org>", "to": ["amit.khaw...@gmail.com"], "subject": "Update", "text": str(testmessage) } ) return r On Monday, 12 November 2012 15:00:43 UTC+5:30, Amit wrote: > > I am getting below error on python shell: > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] > on win32 > Type "copyright", "credits" or "license()" for more information. > >>> import requests > > Traceback (most recent call last): > File "<pyshell#0>", line 1, in <module> > import requests > ImportError: No module named requests > >>> > > but I have installed requests module to my Pythonpath : > > C:\Python27\Lib\site-packages\requests-0.13.8 > > > > On Monday, 12 November 2012 14:47:19 UTC+5:30, Niphlod wrote: >> >> do you have the requests module available on python ? >> >> i.e. if you open a python shell, what you get when you do >> >> import requests >> >> ? >> >> Il giorno lunedì 12 novembre 2012 10:12:08 UTC+1, Amit ha scritto: >>> >>> Hi, >>> >>> I am using scheduler in my application which will periodically sends >>> mail to the user, but when i start worker on command prompt using web2py.py >>> -K MyApp, its giving follwoing error on command prompt: >>> >>> D:\web2py2.1.1\web2py>web2py.py -K MyApp >>> No handlers could be found for logger "web2py" >>> web2py Web Framework >>> Created by Massimo Di Pierro, Copyright 2007-2012 >>> Version 2.1.1 (2012-10-15 12:44:40) stable >>> Database drivers available: SQLite(sqlite3), MySQL(pymysql), PostgreSQL( >>> pg8000), >>> IMAP(imaplib) >>> starting single-scheduler for "MyApp"... >>> Traceback (most recent call last): >>> File "D:\web2py2.1.1\web2py\gluon\restricted.py", line 209, inrestricted >>> exec ccode in environment >>> File "applications\MyApp\models\db.py", line 48, in <module> >>> import requests >>> File "D:\web2py2.1.1\web2py\gluon\custom_import.py", line 70, >>> incustom_import >>> er >>> raise ImportError, 'Cannot import module %s' % str(e) >>> ImportError: Cannot import module 'requests' >>> >>> Below are the code of scheduler and function: >>> >>> db.scheduler_task.validate_and_insert( >>> function_name='send_mail', >>> args='[]', >>> repeats = 0, # run indifinitely >>> period = 60, # every 2 mins >>> timeout = 120, # should take less than 120 seconds >>> ) >>> >>> def send_mail(): >>> message = 'Hello' >>> post_message(message) >>> >>> from mailgun import * >>> import requests >>> def post_message(testmessage): >>> >>> r = requests.post(("https://api.mailgun.net/v2/amit.mailgun.org/" >>> "messages"), >>> auth=("api", "key-3k7c-lqsdfssssnphzid4rbmnr9vp913y9q94"), >>> data={ >>> "from": "Excited User <am...@amit.mailgun.org>", >>> "to": ["amit.k...@gmail.com"], >>> "subject": "Update", >>> "text": str(testmessage) >>> } >>> ) >>> return r >>> >>> >>> And when i keep statement import requests inside post_message() function >>> then the error is not displaying on the command prompt , it seems like >>> worker has started successfully but when I checked in verified in database >>> the task status is showing as FAILED and when I see the stack trace ,its >>> displaying the same error as above. >>> >>> Can anyone guide me to solve this issue? >>> >>> >>> >>> >>> --