-3

I am getting the msg: there is an error in your program: expected an indented block in here line 4, print data.

class listener(StreamListener):
    def on_data(self, data):
        try:
        print data
        saveFile = open('UkmDB','a')
        saveFile.write(data)
        saveFile.write('\n')
        saveFile.close()
        return True
    except BaseException, e:
        print 'failed ondata,',str(e)
        time.sleep(5)
user2390182
  • 72,016
  • 6
  • 67
  • 89
  • 3
    you need to indent after `try:` and the `expect` must be at the same level – user2390182 Feb 13 '17 at 07:45
  • 1
    Your indentation is certainly wrong in this post. Are you mixing tabs and spaces, and have tabs configured to expand to every 4th column perhaps? Don't do that, only use spaces for indentation. – Martijn Pieters Feb 13 '17 at 07:46
  • Possible duplicate of [Why am I getting "IndentationError: expected an indented block"?](http://stackoverflow.com/questions/4446366/why-am-i-getting-indentationerror-expected-an-indented-block) – l'L'l Feb 13 '17 at 07:50

2 Answers2

1

After the try: you need to indent:

class listener(StreamListener):
    def on_data(self, data):
        try:
            print data
            saveFile = open('UkmDB','a')
            saveFile.write(data)
            saveFile.write('\n')
            saveFile.close()
            return True
        except BaseException, e:
            print 'failed ondata,',str(e)
            time.sleep(5)
akkatracker
  • 1,397
  • 3
  • 14
  • 25
0
class listener(StreamListener):
  def on_data(self, data):
    try:
        print data
        saveFile = open('UkmDB','a')
        saveFile.write(data)
        saveFile.write('\n')
        saveFile.close()
        return True
    except BaseException, e:
        print 'failed ondata,',str(e)
        time.sleep(5)
San
  • 161
  • 3
  • 13