Please make sure the description is worded well enough to be understood with as much context and examples as possible.
Code to replicate the error must be provided below.
Instagram responds with 'Unable to get csrf from init request.'
I saw there was another issue created here about it but couldn't find a solution. Doing a simple task for a client of mine, monitoring a single Instagram page for new posts. I'm new to Instagram scraping and this library in general so please let me know if there's something I'm missing. If needed, I can make an account and authenticate through it, but it increases the complexity when I would rather try to avoid it.
Thanks for your help in advance.
Paste the output of python -V here:
import _frozen_importlib # frozen
import _imp # builtin
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import '_warnings' # <class '_frozen_importlib.BuiltinImporter'>
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
import '_io' # <class '_frozen_importlib.BuiltinImporter'>
import 'marshal' # <class '_frozen_importlib.BuiltinImporter'>
import 'nt' # <class '_frozen_importlib.BuiltinImporter'>
import 'winreg' # <class '_frozen_importlib.BuiltinImporter'>
import '_frozen_importlib_external' # <class '_frozen_importlib.FrozenImporter'>
# installing zipimport hook
import 'time' # <class '_frozen_importlib.BuiltinImporter'>
import 'zipimport' # <class '_frozen_importlib.FrozenImporter'>
# installed zipimport hook
# C:\Program Files\Python310\lib\encodings\__pycache__\__init__.cpython-310.pyc matches C:\Program Files\Python310\lib\encodings\__init__.py
# code object from 'C:\\Program Files\\Python310\\lib\\encodings\\__pycache__\\__init__.cpython-310.pyc'
# C:\Program Files\Python310\lib\__pycache__\codecs.cpython-310.pyc matches C:\Program Files\Python310\lib\codecs.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\codecs.cpython-310.pyc'
import '_codecs' # <class '_frozen_importlib.BuiltinImporter'>
import 'codecs' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC8361EE00>
# C:\Program Files\Python310\lib\encodings\__pycache__\aliases.cpython-310.pyc matches C:\Program Files\Python310\lib\encodings\aliases.py
# code object from 'C:\\Program Files\\Python310\\lib\\encodings\\__pycache__\\aliases.cpython-310.pyc'
import 'encodings.aliases' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836743A0>
import 'encodings' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC8361EC50>
# C:\Program Files\Python310\lib\encodings\__pycache__\utf_8.cpython-310.pyc matches C:\Program Files\Python310\lib\encodings\utf_8.py
# code object from 'C:\\Program Files\\Python310\\lib\\encodings\\__pycache__\\utf_8.cpython-310.pyc'
import 'encodings.utf_8' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC8361E9B0>
# C:\Program Files\Python310\lib\encodings\__pycache__\cp1252.cpython-310.pyc matches C:\Program Files\Python310\lib\encodings\cp1252.py
# code object from 'C:\\Program Files\\Python310\\lib\\encodings\\__pycache__\\cp1252.cpython-310.pyc'
import 'encodings.cp1252' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836744F0>
import '_signal' # <class '_frozen_importlib.BuiltinImporter'>
# C:\Program Files\Python310\lib\__pycache__\io.cpython-310.pyc matches C:\Program Files\Python310\lib\io.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\io.cpython-310.pyc'
# C:\Program Files\Python310\lib\__pycache__\abc.cpython-310.pyc matches C:\Program Files\Python310\lib\abc.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\abc.cpython-310.pyc'
import '_abc' # <class '_frozen_importlib.BuiltinImporter'>
import 'abc' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC83674970>
import 'io' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC83674760>
# C:\Program Files\Python310\lib\__pycache__\site.cpython-310.pyc matches C:\Program Files\Python310\lib\site.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\site.cpython-310.pyc'
# C:\Program Files\Python310\lib\__pycache__\os.cpython-310.pyc matches C:\Program Files\Python310\lib\os.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\os.cpython-310.pyc'
# C:\Program Files\Python310\lib\__pycache__\stat.cpython-310.pyc matches C:\Program Files\Python310\lib\stat.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\stat.cpython-310.pyc'
import '_stat' # <class '_frozen_importlib.BuiltinImporter'>
import 'stat' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC83676BC0>
# C:\Program Files\Python310\lib\__pycache__\_collections_abc.cpython-310.pyc matches C:\Program Files\Python310\lib\_collections_abc.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\_collections_abc.cpython-310.pyc'
import '_collections_abc' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC83676EF0>
# C:\Program Files\Python310\lib\__pycache__\ntpath.cpython-310.pyc matches C:\Program Files\Python310\lib\ntpath.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\ntpath.cpython-310.pyc'
# C:\Program Files\Python310\lib\__pycache__\genericpath.cpython-310.pyc matches C:\Program Files\Python310\lib\genericpath.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\genericpath.cpython-310.pyc'
import 'genericpath' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836BD930>
import 'ntpath' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836770A0>
import 'os' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836757E0>
# C:\Program Files\Python310\lib\__pycache__\_sitebuiltins.cpython-310.pyc matches C:\Program Files\Python310\lib\_sitebuiltins.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\_sitebuiltins.cpython-310.pyc'
import '_sitebuiltins' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC83676830>
Processing user site-packages
Adding directory: 'C:\\Users\\Owner\\AppData\\Roaming\\Python\\Python310\\site-packages'
Processing .pth file: 'C:\\Users\\Owner\\AppData\\Roaming\\Python\\Python310\\site-packages\\google_api_core-2.8.2-py3.10-nspkg.pth'
# C:\Program Files\Python310\lib\__pycache__\types.cpython-310.pyc matches C:\Program Files\Python310\lib\types.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\types.cpython-310.pyc'
import 'types' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836BF940>
# C:\Program Files\Python310\lib\importlib\__pycache__\__init__.cpython-310.pyc matches C:\Program Files\Python310\lib\importlib\__init__.py
# code object from 'C:\\Program Files\\Python310\\lib\\importlib\\__pycache__\\__init__.cpython-310.pyc'
# C:\Program Files\Python310\lib\__pycache__\warnings.cpython-310.pyc matches C:\Program Files\Python310\lib\warnings.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\warnings.cpython-310.pyc'
import 'warnings' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836BF130>
import 'importlib' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836BF400>
# C:\Program Files\Python310\lib\importlib\__pycache__\util.cpython-310.pyc matches C:\Program Files\Python310\lib\importlib\util.py
# code object from 'C:\\Program Files\\Python310\\lib\\importlib\\__pycache__\\util.cpython-310.pyc'
# C:\Program Files\Python310\lib\importlib\__pycache__\_abc.cpython-310.pyc matches C:\Program Files\Python310\lib\importlib\_abc.py
# code object from 'C:\\Program Files\\Python310\\lib\\importlib\\__pycache__\\_abc.cpython-310.pyc'
import 'importlib._abc' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836BE080>
# C:\Program Files\Python310\lib\__pycache__\contextlib.cpython-310.pyc matches C:\Program Files\Python310\lib\contextlib.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\contextlib.cpython-310.pyc'
# C:\Program Files\Python310\lib\collections\__pycache__\__init__.cpython-310.pyc matches C:\Program Files\Python310\lib\collections\__init__.py
# code object from 'C:\\Program Files\\Python310\\lib\\collections\\__pycache__\\__init__.cpython-310.pyc'
import 'itertools' # <class '_frozen_importlib.BuiltinImporter'>
# C:\Program Files\Python310\lib\__pycache__\keyword.cpython-310.pyc matches C:\Program Files\Python310\lib\keyword.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\keyword.cpython-310.pyc'
import 'keyword' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836E7790>
# C:\Program Files\Python310\lib\__pycache__\operator.cpython-310.pyc matches C:\Program Files\Python310\lib\operator.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\operator.cpython-310.pyc'
import '_operator' # <class '_frozen_importlib.BuiltinImporter'>
import 'operator' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836E7820>
# C:\Program Files\Python310\lib\__pycache__\reprlib.cpython-310.pyc matches C:\Program Files\Python310\lib\reprlib.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\reprlib.cpython-310.pyc'
import 'reprlib' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836E7A30>
import '_collections' # <class '_frozen_importlib.BuiltinImporter'>
import 'collections' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836E4700>
# C:\Program Files\Python310\lib\__pycache__\functools.cpython-310.pyc matches C:\Program Files\Python310\lib\functools.py
# code object from 'C:\\Program Files\\Python310\\lib\\__pycache__\\functools.cpython-310.pyc'
import '_functools' # <class '_frozen_importlib.BuiltinImporter'>
import 'functools' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC83724760>
import 'contextlib' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836BDE10>
import 'importlib.util' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836BEB30>
# C:\Program Files\Python310\lib\importlib\__pycache__\machinery.cpython-310.pyc matches C:\Program Files\Python310\lib\importlib\machinery.py
# code object from 'C:\\Program Files\\Python310\\lib\\importlib\\__pycache__\\machinery.cpython-310.pyc'
import 'importlib.machinery' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC836E50F0>
# possible namespace for C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\google
Processing .pth file: 'C:\\Users\\Owner\\AppData\\Roaming\\Python\\Python310\\site-packages\\googleapis_common_protos-1.56.4-py3.10-nspkg.pth'
# possible namespace for C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\google
# destroy google
# possible namespace for C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\google
# destroy google
# possible namespace for C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\google\logging
Processing .pth file: 'C:\\Users\\Owner\\AppData\\Roaming\\Python\\Python310\\site-packages\\matplotlib-3.7.2-py3.10-nspkg.pth'
Processing .pth file: 'C:\\Users\\Owner\\AppData\\Roaming\\Python\\Python310\\site-packages\\zope.event-4.6-py3.9-nspkg.pth'
# possible namespace for C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\zope
Processing .pth file: 'C:\\Users\\Owner\\AppData\\Roaming\\Python\\Python310\\site-packages\\zope.interface-5.5.2-py3.10-nspkg.pth'
# possible namespace for C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\zope
# destroy zope
Processing global site-packages
Adding directory: 'C:\\Program Files\\Python310'
Adding directory: 'C:\\Program Files\\Python310\\lib\\site-packages'
Processing .pth file: 'C:\\Program Files\\Python310\\lib\\site-packages\\distutils-precedence.pth'
import 'site' # <_frozen_importlib_external.SourceFileLoader object at 0x000001FC83675180>
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import 'atexit' # <class '_frozen_importlib.BuiltinImporter'>
>>>
Code:
from instagram_web_api import Client, ClientCompatPatch, ClientError, ClientLoginError
user_id = '10353929987'
# Without any authentication
web_api = Client(auto_patch=False, drop_incompat_keys=False)
user_feed_info = web_api.user_feed(user_id, count=10)
for post in user_feed_info:
print('%s from %s' % (post['link'], post['user']['username']))
Error/Debug Log:
web_api = Client(auto_patch=False, drop_incompat_keys=False)
File "C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\instagram_web_api\client.py", line 137, in __init__
self.init()
File "C:\Users\Owner\AppData\Roaming\Python\Python310\site-packages\instagram_web_api\client.py", line 370, in init
raise ClientError('Unable to get csrf from init request.')
instagram_web_api.errors.ClientError: Unable to get csrf from init request.
PS C:\Users\Owner\Desktop\projects\legoMonitor>
Please follow the guide below
x
into all the boxes [ ] relevant to your issue (==> [x] NO spaces).Before submitting an issue, make sure you have:
Which client are you using?
instagram_private_api/
)instagram_web_api/
)Describe the Bug/Error:
Please make sure the description is worded well enough to be understood with as much context and examples as possible.
Code to replicate the error must be provided below.
Instagram responds with
'Unable to get csrf from init request.'
I saw there was another issue created here about it but couldn't find a solution. Doing a simple task for a client of mine, monitoring a single Instagram page for new posts. I'm new to Instagram scraping and this library in general so please let me know if there's something I'm missing. If needed, I can make an account and authenticate through it, but it increases the complexity when I would rather try to avoid it.
Thanks for your help in advance.
Paste the output of
python -V
here:Code:
Error/Debug Log: