fix: make instagrapi import lazy to prevent app crash if missing
This commit is contained in:
@@ -8,14 +8,23 @@ import time
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from instagrapi import Client
|
||||
from instagrapi.exceptions import (
|
||||
ChallengeRequired,
|
||||
PleaseWaitFewMinutes,
|
||||
LoginRequired,
|
||||
UserNotFound,
|
||||
PrivateAccount
|
||||
)
|
||||
try:
|
||||
from instagrapi import Client
|
||||
from instagrapi.exceptions import (
|
||||
ChallengeRequired,
|
||||
PleaseWaitFewMinutes,
|
||||
LoginRequired,
|
||||
UserNotFound,
|
||||
PrivateAccount
|
||||
)
|
||||
except ImportError:
|
||||
Client = None
|
||||
ChallengeRequired = Exception
|
||||
PleaseWaitFewMinutes = Exception
|
||||
LoginRequired = Exception
|
||||
UserNotFound = Exception
|
||||
PrivateAccount = Exception
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from ..config import settings
|
||||
@@ -240,6 +249,10 @@ class InstaParserWorker:
|
||||
def setup_client(self, login: str, password: str, proxy: str | None) -> bool:
|
||||
if self.client:
|
||||
return True
|
||||
|
||||
if Client is None:
|
||||
logger.error("instagrapi is not installed! Cannot setup client.")
|
||||
raise Exception("Module instagrapi is not installed. Please install it.")
|
||||
|
||||
self.client = Client()
|
||||
if proxy:
|
||||
|
||||
Reference in New Issue
Block a user