来自Heroku的这个Python bot的缩进错误。我看不见? [英] Indentation Error from Heroku for this Python bot. I cannot see?

查看:96
本文介绍了来自Heroku的这个Python bot的缩进错误。我看不见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我在Heroku上部署了一个Python bot,每次我尝试运行它时,都会弹出此错误消息。


2016-12-28 T04:32:08.770156 + 00:00 app [worker.1]:文件bot.py,第43行



2016-12-28 T04:32:08.770168 + 00:00 app [worker.1]:else:



2016-12-28 T04:32:08.770171 + 00:00 app [worker.1]:^



2016-12-28 T04:32 :08.770172 + 00:00 app [worker.1]:IndentationError:预计有一个缩进块

这是它引用的代码块。我明白他们抛出的错误,但看不到原因? (代码来自Git仓库)。

$ p $ 类监听器(StreamListener):
def on_data(self,raw_data) :
try:
retweet_ed = raw_data.lower()。split('retweeted':')[1] .split(','possible_sensitive'')[0] .replace(, ,)
tweet_text = raw_data.lower()。split('text:')[1] .split(',source:'')[0] .replace(, ,)#tweet的文本
screen_name = raw_data.lower()。split('screen_name:'')[1] .split(',location')[0] .replace( ,,)#tweet的作者屏幕名称
tweet_sid = raw_data.split('id:')[1] .split('id_str:')[0] .replace(, ))#tweet的id


如果没有的话(a_acc == screen_name.lower()for a_acc in whitelist_acc):
if any any(acc == screen_name .lower()for acc in banned_accs):
如果不是any(a_wrds在screen_name.lower()中为a_wrds在whitelist_words中):
if没有任何(在tweet_text.lower()中的单词在banned_words中):
if(falsein retweet_ed):
#call你想在这里做什么
#例如:
#fav(tweet_sid)
#retweet(tweet_sid)
其他:
通过
#call你想在这里做什么
#例如:
$ fa(tweet_sid)
#retweet(tweet_sid)
返回True
除了Exception作为e:
print(str(e))#打印错误信息,如果u不希望它评论它
pass

有人可以帮忙吗?给我一个眼睛?或做烤我XD

解决方案

首先,如果 $ c>语句。这是最可能的罪魁祸首,你可以通过在该块中添加 pass 来解决这个问题。如果你想自己测试一下,你可以运行下面这个非常简单的例子,并验证解释器在你运行它时会给出一个错误。

  if 1 == 1:
else:
print永远不会打印。

其次,由于重新编码在SO上很难说,但你也可能混合空格和制表符不正确。如果您使用vim,您可以执行 set list 来显示不可见字符,并确保您的字符一致。


Recently I've deployed a python bot on Heroku and every time I try to run it, this error pops up.

2016-12-28 T04:32:08.770156+00:00 app[worker.1]:File "bot.py", line 43

2016-12-28 T04:32:08.770168+00:00 app[worker.1]: else:

2016-12-28 T04:32:08.770171+00:00 app[worker.1]:^

2016-12-28 T04:32:08.770172+00:00 app[worker.1]: IndentationError: expected an indented block

Here's the code block it refers to. I do understand the error they throwing but can't see the cause? (Code was from a Git repository.)

class listener(StreamListener):
    def on_data(self, raw_data):
        try:
            retweet_ed = raw_data.lower().split('"retweeted":')[1].split(',"possibly_sensitive"')[0].replace(",", "")
            tweet_text = raw_data.lower().split('"text":"')[1].split('","source":"')[0].replace(",", "") #tweet's text
            screen_name = raw_data.lower().split('"screen_name":"')[1].split('","location"')[0].replace(",", "") #tweet's authors screen name
            tweet_sid = raw_data.split('"id":')[1].split('"id_str":')[0].replace(",", "") #tweet's id


            if not any(a_acc == screen_name.lower() for a_acc in whitelist_acc):
                if not any(acc == screen_name.lower() for acc in banned_accs):
                    if not any(a_wrds in screen_name.lower() for a_wrds in whitelist_words):
                        if not any(word in tweet_text.lower() for word in banned_words):
                            if("false" in retweet_ed):
                                #call what u want to do here
                                #for example :
                                #fav(tweet_sid)
                                #retweet(tweet_sid)
                            else:
                                pass
                                #call what u want to do here
                                #for example :
                                #fav(tweet_sid)
                                #retweet(tweet_sid)
            return True
        except Exception as e:
            print(str(e)) # prints the error msg, if u dont want it comment it out
            pass

Can someone help? Give me an eye? or do roast me XD

解决方案

First, you cannot have no code under the if statement. That is the most likely culprit and you can fix this by adding pass in that block. If you want to test this for yourself, you can run the following very simple example and verify that the interpreter gives an error when you try to run it.

if 1 == 1:
else:
    print "This will never print."

Second, it is difficult to tell because of re-encoding on SO, but you may also have mixed spaces and tabs incorrectly. If you are using vim, you can do set list to show the invisible characters and make sure you are consistent.

这篇关于来自Heroku的这个Python bot的缩进错误。我看不见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆