【问题标题】:ValueError: Sample larger than population or is negative [IG BOT]ValueError:样本大于总体或为负 [IG BOT]
【发布时间】:2021-10-10 17:50:06
【问题描述】:

我收到了这个错误:

File "C:\Users\Luca\OneDrive\Desktop\Python\INSTAGRAM BOT FINALE ( FORSE)\Python-Instagram-Bot-Scripts-main\selenium_script.py", line 105, in like_post_by_tag
        choices = random.sample(posts_list, amount)
      File "C:\Program Files\Python39\lib\random.py", line 450, in sample
        raise ValueError("Sample larger than population or is negative")
    ValueError: Sample larger than population or is negative

它适用于 Instagram 机器人,当它试图点击帖子时崩溃

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python anomaly-detection


【解决方案1】:

如果您尝试采样的项目数大于您从中采样的项目数,那么您将遇到此 ValueError。您可以处理带有异常except ValueError: choices = random.sample(posts_list, len(posts_list)) 的错误,然后使用较低的值重新采样,例如posts_list 的大小num_posts_list = len(posts_list),或者您可以在采样之前检查posts_list 的大小,然后减少数量。 if amount > num_posts_list: amount = num_posts_list

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2015-06-27
    • 2016-02-11
    • 2022-01-10
    • 1970-01-01
    • 2014-01-18
    • 2012-11-13
    相关资源
    最近更新 更多