在 Heroku 服务器上使用 Selenium 访问 Facebook 时,用户已超出 'max_questions' 资源错误

User has exceeded the 'max_questions' resource error when accessing Facebook with Selenium on Heroku server

我正在尝试将来自 Messenger 的所有消息及其发件人全天候 运行 存储在数据库中。 下面的代码缩写为 ver。仅获取存储在数据库中的发件人以将它们与新发件人进行比较的整个代码。

我的问题是:

当我使用本地 chrome 驱动程序和

执行以下代码时
driver = webdriver.Chrome('/Users/USER/Projects/seleniumBeta/chromedriver 15-24-35-680', chrome_options=chrome_options)

程序成功从数据库中获取数据。 但是当我 运行 在 heroku 上使用

以下代码时

heroku 运行 python3 app.py

from sqlalchemy import create_engine, text
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
import os

...

database = create_engine(DB_URL, encoding='utf-8', max_overflow=0)
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=chrome_options)

globalURL = 'https://www.messenger.com/t/101210925710184'
driver.get(globalURL)   


(... LOGIN CODES)

def repeater():
    senders = [sender['name'] for sender in database.execute(text("SELECT * FROM senders")).fetchall()]
    return repeater()

repeater()

应用无法获取发件人并出现以下错误:

sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1226, "User 'b715fbc9127dd4' has exceeded the 'max_questions' resource (current value: 3600)")

当我允许未知设备从本地设备上的 Facebook 页面登录后,就会发生这种情况。

我很乐意在这里听到任何建议。谢谢!

这个错误信息...

sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1226, "User 'b715fbc9127dd4' has exceeded the 'max_questions' resource (current value: 3600)")

......表示主机将每个用户的连接数限制为每小时 3600,但您的程序已超过该值。


解决方案

您可以尝试以下几个步骤:

  • create_engine() 内或从 phpmyadmin 设置以下内容:

    • @MAX_QUESTIONS=0; # 这将设置无限 'max_questions'
    • FLUSH PRIVILEGES;
  • 由于max_questions设置了每小时一定的请求数,需要一个小时后才需要重试。