selfteaching / selfteaching/selfteaching-python-camp

Day12 微信网页登录成功之后,报错IndexError: list index out of range

Open
#1,271 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
151
Forks
875
PR merge metrics
No merged PRs in 30d

Description

通过扫描登录网页版微信之后,紧接着就报错了!具体报错信息:

Traceback (most recent call last):
  File "d12_training2.py", line 8, in <module>
    my_friend = bot.friends().search('Somebody')[0]
IndexError: list index out of range

查了报错原因,有一种可能:list本身就是一个空的,没有一个元素,所以当访问到list[0]的时候,就会出现该错误。
尝试:我将

my_friend = bot.friends().search('somebody')[0]
my_friend.send('请给我分享一篇文章')  

改为特定的好友

my_friend = bot.friends().search('三碗饭')[0]
my_friend.send('请给我分享一篇文章')

三碗饭接到要求分享的消息请求,分享后得到下面的信息。

In [1]: Building prefix dict from the default dictionary ...
Dumping model to file cache /var/folders/yp/pwt2r68s0rx8m7th28rq7l140000gp/T/jieba.cache
Loading model cost 1.016 seconds.
Prefix dict has been built succesfully.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with d12_training2.py at line 8 and reproduce the post-login friends().search call. Compare the searches for “Somebody”, “somebody”, and “三碗饭”, verifying whether the result is empty before [0] is accessed; done means the cause of the IndexError and the required lesson change are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.