Closed animemoeus closed 3 years ago
May I know which server you're talking about ? VPS ?
May I know which server you're talking about ? VPS ?
I'm using VPS with centos operating system.
ouch
I think the problem is in the requests
module.
From my local:
>>> link = 'https://www.instagram.com/accounts/login/'
>>> response = requests.get(link)
>>> response.cookies['csrftoken']
'ewTzPVLwmequM3gAQt1JYyTQK6jp4krn'
>>>
>>> response.cookies
<RequestsCookieJar[Cookie(version=0, name='csrftoken', value='PyGCLpaCB6gJGmnZdug4SEGexH79rHkm', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1637834075, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='ig_did', value='00FAF7DD-5FB4-4D81-9073-2F7421BC0065', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669456475, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False), Cookie(version=0, name='ig_nrcb', value='1', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1637920475, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='mid', value='X797WgAEAAFepiuHKUYctKgf7_Hn', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669456475, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]>
>>> response.cookies['csrftoken']
'PyGCLpaCB6gJGmnZdug4SEGexH79rHkm'
>>>
From VPS:
>>> import requests
>>> link = 'https://www.instagram.com/accounts/login/'
>>> response = requests.get(link)
>>> response.cookies['csrftoken']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tendean/virtualenv/repositories/animemoeus/3.7/lib/python3.7/site-packages/requests/cookies.py", line 328, in __getitem__
return self._find_no_duplicates(name)
File "/home/tendean/virtualenv/repositories/animemoeus/3.7/lib/python3.7/site-packages/requests/cookies.py", line 399, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='csrftoken', domain=None, path=None"
>>>
>>> response.cookies
<RequestsCookieJar[Cookie(version=0, name='ig_did', value='1AC2D5E5-69B6-422B-802C-701595D56480', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669456390, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False), Cookie(version=0, name='ig_nrcb', value='1', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1637920390, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='mid', value='X797BgAEAAFcjrtl69ZapsVXk7TV', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669456390, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]>
>>> response.cookies['ig_did']
'1AC2D5E5-69B6-422B-802C-701595D56480'
>>>
Hey @animemoeus, Currently I don't have a vps, I will check this asap.
Solved after I move to Ubuntu server.
I also found another way to get csrftoken in my centos server
>>> import requests
>>> a = requests.get('https://www.instagram.com/accounts/login/')
>>> a.cookies
<RequestsCookieJar[Cookie(version=0, name='ig_did', value='DB62594A-08DD-4001-926D-A043874056FF', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669632740, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False), Cookie(version=0, name='ig_nrcb', value='1', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1638096740, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='mid', value='X8Ir5AAEAAF-1iu-Xc1R_jh2do8m', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669632740, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]>
>>> a = requests.get('https://www.instagram.com/')
>>> a.cookies
<RequestsCookieJar[Cookie(version=0, name='csrftoken', value='sOO91naDnZMEhsRXM4UpfG3xlGRyODlO', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1638010363, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='ig_did', value='0A9A1F5A-08C3-46F2-B030-98E903ADF1E4', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669632763, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False), Cookie(version=0, name='ig_nrcb', value='1', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1638096763, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='mid', value='X8Ir-wAEAAG3zgp3uOWVFB5jCozx', port=None, port_specified=False, domain='.instagram.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=1669632763, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]>
>>>
It's working on my computer, but not working on the server.