python IndexError: tuple index out of range

 def _requests_(self,title_list,link_list,time_list,args):

        for num in range(0,len(time_list)):
             #
             # sql="select id  from news_source where publishTime=%s and link=%s ;"%(time_list[num],link_list[num])
             # self.cursor.execute(sql)
             # account_result = self.cursor.fetchone()
             # if account_result ==None:
                 result = requests.get(
                     "https://project.test.ethercap.com/spider/news/save-source?title={}&link={}&logo={}&publishTime={}&source={}".format(
                         title_list[num], link_list[num], time_list[num], args))
                 time.sleep(2)
                 print (result)
                 
                 

我传递的3个列表,但是报错,求指教,谢谢

Traceback (most recent call last):
File "36kr.py", line 502, in <module>

kr().get_36kr_content()

File "36kr.py", line 78, in get_36kr_content

self._requests_(title_list, link_list, time_list, "36kr")

File "36kr.py", line 490, in requests

title_list[num], link_list[num], time_list[num], args))

IndexError: tuple index out of range

阅读 8k
1 个回答

format字符串里有5个{},但是你传了4个参数.

In [1]: "{}{}".format(1)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-1-47f9e2ea3532> in <module>()
----> 1 "{}{}".format(1)

IndexError: tuple index out of range

就这样.细心点朋友.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题