1

This script has been working fine, however now when I go to execute it, it fails to compile with:

  File "/Users/camerongordon/Desktop/Python Scripts/hello.py", line 12
    def ConnectToDatabase(): 
    ^
IndentationError: expected an indented block

Here is the script:

import tornado.ioloop
import tornado.web
from tornado.httpclient import AsyncHTTPClient
from tornado import gen 
from tornado.options import define, options 
from apscheduler.schedulers.tornado import TornadoScheduler
from torndb import Connection

class MainHandler(tornado.web.RequestHandler):
    def get(self):

def ConnectToDatabase(): 
   db = Connection("127.0.0.1", 'helloworld', user='root', password='')
   return db

application = tornado.web.Application
([
    (r"/", MainHandler),
])

def ProcessQueue:

def main(): 
    # http://stackoverflow.com/questions/29316173/apscheduler-run-async-function-in-tornado-python
    # https://github.com/teriyakichild/example-scheduler/blob/master/example_scheduler/__init__.py

    application.listen(8888)

    db = ConnectToDatabase() 

    scheduler = TornadoScheduler()

    scheduler.add_job(ProcessQueue, 'interval', name='tick-interval-3-seconds', seconds=4, timezone='America/Chicago')

    scheduler.start()

    tornado.ioloop.IOLoop.current().start()

if __name__ == "__main__":
    main(); 

What is going on? Everything looks syntactically correct and indented properly.

user3776241
  • 501
  • 8
  • 20

2 Answers2

3
class MainHandler(tornado.web.RequestHandler):
    def get(self):

def ConnectToDatabase(): 
   db = Connection("127.0.0.1", 'helloworld', user='root', password='')
   return db

Your def get(self): calls for a method body to come; if you add pass, things will work. You probably, by accident, omitted or deleted some code:

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        pass

def ConnectToDatabase(): 
   db = Connection("127.0.0.1", 'helloworld', user='root', password='')
   return db

Also, your indents are unequal -- that's not a good sign. Use a proper editor.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • The [official style guide](https://www.python.org/dev/peps/pep-0008/) states indents should be 4 spaces. Make sure to configure a proper editor (such as Sublime Text, Notepad++, vim, emacs, etc.) for this when programming in Python. – Alyssa Haroldsen Jul 10 '15 at 22:13
0

Can you try highlighting your script and converting all indentation to tabs? Sublime has an option for that. Also, you def get(): doesn't have a body.

Ryan
  • 354
  • 3
  • 18