小编Jas*_*ngh的帖子

Telegram API 抛出 PeerFloodError:请求过多

我没有使用机器人 API。我正在使用 Telegram API 发送消息。消息很容易发送,但问题出现在 19 个用户之后。在第 20 个用户上,我收到 PeerFloodError。即使在搜索了很多之后,我也没有找到任何特定的限制,并且使用 sleep 也不起作用。请提出一种克服这个问题的方法。

代码

def send_message(root2, client):
    totalcount = 0
    for user in users:
        if totalcount >= len(users):
            root2.destroy()
            break

        if totalcount % 15 == 0 and totalcount != 0:
            print("Waiting for one minute...")
            time.sleep(60)

        if user not in users2 or user not in users3:
            totalcount += 1
            entity = client.get_entity(user)

            client.send_message(entity, message_str)
            time.sleep(8)
Run Code Online (Sandbox Code Playgroud)

python-3.x telegram python-telegram-bot telegram-bot telethon

4
推荐指数
1
解决办法
8320
查看次数

在 Django 的模板中显示模型的计算值

我想在每个产品下显示计算的折扣。下面的代码没有错误,但不显示值。

模型.py

from django.db import models
# Create your models here.
CATEGORIES = (  
    ('Electronics', 'Electronics'),
    ('Clothing', 'Clothing'),
)

class Products(models.Model):
    Image = models.FileField()
    ProductName = models.CharField(max_length = 250, default='')
    Brand = models.CharField(max_length = 250, default='')
    OriginalPrice = models.IntegerField(default = '')
    Price = models.IntegerField(default = '')
    Category = models.CharField(max_length = 250, choices = CATEGORIES)

    class Meta:
        verbose_name = 'Product'
        verbose_name_plural = 'Products'

    def DiscountCalc(self):
        Discount = (Price/OriginalPrice) * 100
        return self.Discount

    def __str__ (self):
        return self.ProductName
Run Code Online (Sandbox Code Playgroud)

这是模板 index.html: …

django django-templates django-models

0
推荐指数
1
解决办法
1322
查看次数