Python Reddit Praw

Python Reddit Praw,python,reddit,Python,Reddit,我正在尝试制作代码,从reddit获取链接和字符串并显示它们。我接受了代码,但它返回了一个错误: Traceback (most recent call last): File "epst4.py", line 20, in <module> with open('/home/pi/project/display.html', 'w') as f:f.write(template.format(imgURL, wittyText)) IndexError: t

我正在尝试制作代码,从reddit获取链接和字符串并显示它们。我接受了代码,但它返回了一个错误:

Traceback (most recent call last):
    File "epst4.py", line 20, in <module>
    with open('/home/pi/project/display.html', 'w') as f:f.write(template.format(imgURL, wittyText))
    IndexError: tuple index out of range

第19行缺少撇号
/home/pi/project/template.html'
谢谢。我来编辑!但是,即使我补充说这是同一个问题。您的template.html是否仅指{0}和{1}或还指缺少的{2}?我们还需要查看
template.html
display.html
的源代码。
import os, praw, random, requests, time

r = praw.Reddit(client_id='abc',client_secret='abc', password = 'abc', user_agent = 'abc',username='abc')
getCount = 25

while True:
    earthpornSub = r.get_subreddit('earthporn')
    showerthoughtSub = r.get_subreddit('showerthoughts')

    earthpornContent = earthpornSub.get_top_from_week(limit = getCount)
    showerthoughtContent = showerthoughtSub.get_top_from_week(limit = getCount)

    earthpornList = [sub for sub in earthpornContent]
    showerthoughtList = [sub for sub in showerthoughtContent]

    imgURL = earthpornList[random.randint(0, getCount - 1)].url
    wittyText = showerthoughtList[random.randint(0, getCount - 1)].title  # They're typically supposed to be all in the title

    with open('/home/pi/project/template.html', 'r') as f: template = f.read()
    with open('/home/pi/project/display.html', 'a') as f: f.write(template.format(imgURL, wittyText))

    time.sleep(60)