Answer the question
In order to leave comments, you need to log in
How to fix 302 error after submitting an API request?
I use the necessary requests to connect to insta:
import requests
r = requests.get(
url='https://i.instagram.com/api/v1/feed/reels_tray/',
headers={
'Host': 'i.instagram.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0',
'X-IG-App-ID': '936619743392459',
'X-ASBD-ID': '437806',
'X-IG-WWW-Claim': 'hmac.AR1mC3BljF1XvKUF2ZN29mo7M-gTCU0tJ8b4dDml6MZsT0FC',
'Referer': 'https://www.instagram.com/',
'Cookie': 'csrftoken: "wjWEYcw044iKoejKa7LjbyCjiBZ3lUOq"'
'ds_user_id: "1066075764"'
'ig_did: "D7ABA642-7272-4355-9946-10C0320EA158"'
'mid: "YSjKXgALAAEOXiNSnMLLwokm5YLm"'
'sessionid: "1066075764:x2veTN4WOKUT92:23"',
'Accept': '*/*',
},
allow_redirects=False
)
print(r.status_code) # 302
Answer the question
In order to leave comments, you need to log in
If you look at the location, you can see what throws out for authorization. Cookies don't get transferred that way at all.
Make your cookies a name-value dictionary
and pass them into the request
cookies = {'name': 'value', 'name2': 'value2'}
r = requests.get(url, cookies=cookies)
Well, actually the HTTP 302 response code is not an error, it's a harmless redirect. The one that you disable with the allow_redirects=False parameter, although by default requests handles them just fine on its own. Do you have any special reasons for not allowing the library to do this?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question