mirror of
https://github.com/instaloader/instaloader.git
synced 2024-11-04 09:22:29 +01:00
Update doc section Troubleshooting -> Login Error
New Firefox cookie import script, based on a comment in #615: https://github.com/instaloader/instaloader/issues/615#issuecomment-630127064
This commit is contained in:
parent
72d86533f2
commit
27b7c98be2
53
docs/codesnippets/615_import_firefox_session.py
Normal file
53
docs/codesnippets/615_import_firefox_session.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
from argparse import ArgumentParser
|
||||||
|
from glob import glob
|
||||||
|
from os.path import expanduser
|
||||||
|
from platform import system
|
||||||
|
from sqlite3 import OperationalError, connect
|
||||||
|
|
||||||
|
try:
|
||||||
|
from instaloader import ConnectionException, Instaloader
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
raise SystemExit("Instaloader not found.\n pip install [--user] instaloader")
|
||||||
|
|
||||||
|
|
||||||
|
def get_cookiefile() -> str:
|
||||||
|
default_cookiefile = {
|
||||||
|
"Windows": "~/AppData/Roaming/Mozilla/Firefox/Profiles/*/cookies.sqlite",
|
||||||
|
"Darwin": "~/Library/Application Support/Firefox/Profiles/*.default/cookies.sqlite",
|
||||||
|
}.get(system(), "~/.mozilla/firefox/*.default/cookies.sqlite")
|
||||||
|
cookiefiles = glob(expanduser(default_cookiefile))
|
||||||
|
if not cookiefiles:
|
||||||
|
raise SystemExit("No Firefox cookies.sqlite file found. Use -c COOKIEFILE.")
|
||||||
|
return cookiefiles[0]
|
||||||
|
|
||||||
|
|
||||||
|
def import_session(cookiefile, sessionfile):
|
||||||
|
print(f"Using cookies from {cookiefile}.")
|
||||||
|
conn = connect(cookiefile)
|
||||||
|
try:
|
||||||
|
cookie_data = conn.execute(
|
||||||
|
"SELECT name, value FROM moz_cookies WHERE baseDomain='instagram.com'"
|
||||||
|
)
|
||||||
|
except OperationalError:
|
||||||
|
cookie_data = conn.execute(
|
||||||
|
"SELECT name, value FROM moz_cookies WHERE host LIKE '%instagram.com'"
|
||||||
|
)
|
||||||
|
instaloader = Instaloader(max_connection_attempts=1)
|
||||||
|
instaloader.context._session.cookies.update(cookie_data)
|
||||||
|
username = instaloader.test_login()
|
||||||
|
if not username:
|
||||||
|
raise SystemExit("Not logged in. Are you logged in successfully in Firefox?")
|
||||||
|
print(f"Imported session cookie for {username}.")
|
||||||
|
instaloader.context.username = username
|
||||||
|
instaloader.save_session_to_file(sessionfile)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
p = ArgumentParser()
|
||||||
|
p.add_argument("-c", "--cookiefile")
|
||||||
|
p.add_argument("-f", "--sessionfile")
|
||||||
|
args = p.parse_args()
|
||||||
|
try:
|
||||||
|
import_session(args.cookiefile or get_cookiefile(), args.sessionfile)
|
||||||
|
except (ConnectionException, OperationalError) as e:
|
||||||
|
raise SystemExit(f"Cookie import failed: {e}")
|
@ -1,23 +0,0 @@
|
|||||||
from glob import glob
|
|
||||||
from os.path import expanduser
|
|
||||||
from sqlite3 import connect
|
|
||||||
|
|
||||||
from instaloader import ConnectionException, Instaloader
|
|
||||||
|
|
||||||
# FIREFOXCOOKIEFILE = "/home/alex/.mozilla/firefox/l96w6b90.default/cookies.sqlite"
|
|
||||||
FIREFOXCOOKIEFILE = glob(expanduser("~/.mozilla/firefox/*.default/cookies.sqlite"))[0]
|
|
||||||
|
|
||||||
instaloader = Instaloader(max_connection_attempts=1)
|
|
||||||
instaloader.context._session.cookies.update(connect(FIREFOXCOOKIEFILE)
|
|
||||||
.execute("SELECT name, value FROM moz_cookies "
|
|
||||||
"WHERE baseDomain='instagram.com'"))
|
|
||||||
|
|
||||||
try:
|
|
||||||
username = instaloader.test_login()
|
|
||||||
if not username:
|
|
||||||
raise ConnectionException()
|
|
||||||
except ConnectionException:
|
|
||||||
raise SystemExit("Cookie import failed. Are you logged in successfully in Firefox?")
|
|
||||||
|
|
||||||
instaloader.context.username = username
|
|
||||||
instaloader.save_session_to_file()
|
|
25
docs/conf.py
25
docs/conf.py
@ -49,7 +49,22 @@ autodoc_member_order = 'bysource'
|
|||||||
intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
|
intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
|
||||||
'requests': ('https://requests.kennethreitz.org/en/master/', None)}
|
'requests': ('https://requests.kennethreitz.org/en/master/', None)}
|
||||||
|
|
||||||
extlinks = {'issue': ('https://github.com/instaloader/instaloader/issues/%s', 'issue #')}
|
current_release = subprocess.check_output(["git", "describe", "--abbrev=0"]).decode("ascii")[1:-1]
|
||||||
|
current_release_date = subprocess.check_output(
|
||||||
|
["git", "log", "-1", "--tags", "--format=%ad", "--date=format:%e %b %Y"]).decode("ascii")[:-1]
|
||||||
|
|
||||||
|
html_context = {'current_release': current_release, 'current_release_date': current_release_date}
|
||||||
|
|
||||||
|
extlinks = {
|
||||||
|
'issue': (
|
||||||
|
'https://github.com/instaloader/instaloader/issues/%s',
|
||||||
|
'Issue #'
|
||||||
|
),
|
||||||
|
'example': (
|
||||||
|
'https://raw.githubusercontent.com/instaloader/instaloader/v' + current_release + '/docs/codesnippets/%s',
|
||||||
|
'Example '
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
@ -69,7 +84,7 @@ master_doc = 'index'
|
|||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = 'Instaloader'
|
project = 'Instaloader'
|
||||||
copyright = '2017, Alexander Graf and Andre Koch-Kramer'
|
copyright = '2017-2020, Alexander Graf and Andre Koch-Kramer'
|
||||||
author = 'Alexander Graf and Andre Koch-Kramer'
|
author = 'Alexander Graf and Andre Koch-Kramer'
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
@ -353,12 +368,6 @@ texinfo_documents = [
|
|||||||
# texinfo_no_detailmenu = False
|
# texinfo_no_detailmenu = False
|
||||||
|
|
||||||
|
|
||||||
current_release = subprocess.check_output(["git", "describe", "--abbrev=0"]).decode("ascii")[1:-1]
|
|
||||||
current_release_date = subprocess.check_output(["git", "log", "-1", "--tags", "--format=%ad", "--date=format:%e %b %Y"]).decode("ascii")[:-1]
|
|
||||||
|
|
||||||
html_context = {'current_release': current_release, 'current_release_date': current_release_date}
|
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
typing.TYPE_CHECKING = True
|
typing.TYPE_CHECKING = True
|
||||||
app.add_stylesheet("instaloader.css")
|
app.add_stylesheet("instaloader.css")
|
||||||
|
@ -32,7 +32,7 @@ rate limit has almost been reached, according to Instaloader's own rate
|
|||||||
accounting mechanism. We regularly adjust this mechanism to match Instagram's
|
accounting mechanism. We regularly adjust this mechanism to match Instagram's
|
||||||
current rate limiting.
|
current rate limiting.
|
||||||
|
|
||||||
Login error
|
Login Error
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Instaloader's login *should* work fine, both with and without
|
Instaloader's login *should* work fine, both with and without
|
||||||
@ -40,21 +40,31 @@ Two-Factor-Authentication. It also supports handling the *checkpoint challenge*,
|
|||||||
issued when Instagram suspects authentication activity on your account, by
|
issued when Instagram suspects authentication activity on your account, by
|
||||||
pointing the user to an URL to be opened in a browser.
|
pointing the user to an URL to be opened in a browser.
|
||||||
|
|
||||||
Nevertheless, in :issue:`92` users report problems with logging in. To still use
|
Nevertheless, in :issue:`92` and :issue:`615` users reported problems with
|
||||||
Instaloader's logged-in functionality, you may use the following script to
|
logging in. We recommend to always keep the sessionfile which Instaloader
|
||||||
workaround login problems by importing the session cookies from Firefox and
|
creates when using :option:`--login`. If a sessionfile is present,
|
||||||
bypassing Instaloader's login.
|
:option:`--login` does not make make use of the failure-prone login procedure.
|
||||||
|
Also, sessionfiles usually do not expire and can be copied between different
|
||||||
|
computers without any problems.
|
||||||
|
|
||||||
.. literalinclude:: codesnippets/92_import_firefox_session.py
|
If you do not have a sessionfile present, you may use the following script
|
||||||
|
(:example:`615_import_firefox_session.py`) to workaround login problems by
|
||||||
|
importing the session cookies from Firefox and bypassing Instaloader's login and
|
||||||
|
so still use Instaloader's logged-in functionality.
|
||||||
|
|
||||||
To use this,
|
.. literalinclude:: codesnippets/615_import_firefox_session.py
|
||||||
|
|
||||||
#. login to Instagram in Firefox,
|
To use this script,
|
||||||
|
|
||||||
#. execute the snippet,
|
#. Download the script: :example:`615_import_firefox_session.py`,
|
||||||
|
|
||||||
#. then, ``instaloader -l USERNAME`` should work fine.
|
#. Login to Instagram in Firefox,
|
||||||
|
|
||||||
If you do not use your default firefox profile, or your operating system has the
|
#. Execute the snippet, e.g. with ``python 615_import_firefox_session.py``,
|
||||||
paths differently set up, you may have to alter the ``FIREFOXCOOKIEFILE``
|
|
||||||
variable first.
|
#. Then, ``instaloader -l USERNAME`` should work fine.
|
||||||
|
|
||||||
|
This script also supports specifying a cookiefile path, which may be useful if
|
||||||
|
you use multiple Firefox profiles or if your operating system has the directory
|
||||||
|
structure differently set up. Also, you can specify an alternative sessionfile
|
||||||
|
path.
|
||||||
|
Loading…
Reference in New Issue
Block a user