mirror of
https://github.com/instaloader/instaloader.git
synced 2024-09-11 16:22:24 +02:00
Restructure get_session() error handling
This commit is contained in:
parent
c77d372e74
commit
9aa2b91d52
22
instagram.py
22
instagram.py
@ -22,6 +22,9 @@ class PrivateProfileNotFollowedException(DownloaderException):
|
|||||||
class LoginRequiredException(DownloaderException):
|
class LoginRequiredException(DownloaderException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class LoginException(DownloaderException):
|
||||||
|
pass
|
||||||
|
|
||||||
def log(*msg, sep='', end='\n', flush=False, quiet=False):
|
def log(*msg, sep='', end='\n', flush=False, quiet=False):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(*msg, sep=sep, end=end, flush=flush)
|
print(*msg, sep=sep, end=end, flush=flush)
|
||||||
@ -187,13 +190,11 @@ def get_session(user, passwd, empty_session_only=False, session=None):
|
|||||||
time.sleep(5 * random.random())
|
time.sleep(5 * random.random())
|
||||||
if login.status_code == 200:
|
if login.status_code == 200:
|
||||||
if test_login(user, session):
|
if test_login(user, session):
|
||||||
return session, True
|
return session
|
||||||
else:
|
else:
|
||||||
print('Login error! Check your credentials!', file=sys.stderr)
|
raise LoginException('Login error! Check your credentials!')
|
||||||
return session, False
|
|
||||||
else:
|
else:
|
||||||
print('Login error! Connection error!', file=sys.stderr)
|
raise LoginException('Login error! Connection error!')
|
||||||
return session, False
|
|
||||||
|
|
||||||
def download(name, username = None, password = None, sessionfile = None, \
|
def download(name, username = None, password = None, sessionfile = None, \
|
||||||
profile_pic_only = False, download_videos = True, fast_update = False, \
|
profile_pic_only = False, download_videos = True, fast_update = False, \
|
||||||
@ -221,15 +222,16 @@ def download(name, username = None, password = None, sessionfile = None, \
|
|||||||
if password is None:
|
if password is None:
|
||||||
password = getpass.getpass(
|
password = getpass.getpass(
|
||||||
prompt='Enter your corresponding Instagram password: ')
|
prompt='Enter your corresponding Instagram password: ')
|
||||||
session, status = get_session(username, password, session=session)
|
try:
|
||||||
if status:
|
session = get_session(username, password, session=session)
|
||||||
|
except LoginException as err:
|
||||||
|
print("%s" % err, file=sys.stderr)
|
||||||
|
else:
|
||||||
break
|
break
|
||||||
username = None
|
username = None
|
||||||
password = None
|
password = None
|
||||||
else:
|
else:
|
||||||
session, status = get_session(username, password, session=session)
|
session = get_session(username, password, session=session)
|
||||||
if not status:
|
|
||||||
raise DownloaderException("aborting due to login error")
|
|
||||||
data = get_json(name, session=session)
|
data = get_json(name, session=session)
|
||||||
if not data["entry_data"]["ProfilePage"][0]["user"]["followed_by_viewer"]:
|
if not data["entry_data"]["ProfilePage"][0]["user"]["followed_by_viewer"]:
|
||||||
raise PrivateProfileNotFollowedException("user %s: private but not followed" % name)
|
raise PrivateProfileNotFollowedException("user %s: private but not followed" % name)
|
||||||
|
Loading…
Reference in New Issue
Block a user