pythonmysqlseleniumherokufacebook-messenger

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


I'm trying to store all messages and their senders from messenger in the database running 24/7. The code under is abbreviated ver. of the whole code that only fetches the senders stored in the database to compare them with new senders.

My problem is :

When I execute the following code with a local chrome driver with

driver = webdriver.Chrome('/Users/USER/Projects/seleniumBeta/chromedriver 15-24-35-680', chrome_options=chrome_options)

the program successfully fetches data from database. But when I run the following code on heroku with

heroku run 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()

App fails to fetch senders with the following error:

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

This happens just after when I allow unknown device login from the facebook page on my local device.

I would be glad to hear any advices here. Thanks !


Solution

  • This error message...

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

    ......implies that the host limits the connections per user to 3600 every hour but your program have exceeded the value.


    Solution

    You can try a couple of steps as follows: