简体   繁体   中英

Requests returns Too Many Requests status code

The goal is to return resp.text for the account page

When you run this function you get the response code 429 that indicates too Many Requests were made.

even when running the script with proxychains proxychains python3 file.py it returns the same status code

file.py

import requests

def g3t_usr(acc):
    """ Surf to account page """
    resp = requests.get(f'https://www.instagram.com/{acc}/')

    if resp.status_code == 200:
        return resp.text
    else:
        print (resp.status_code)
    
    return resp.text 
 
acc="<some_random_user>"
g3t_usr(acc)

Does Instagram check for requests made by python requests and flags them

Try Specifying the „User-Agent“ in the header to make your request more „authentic“ like this: requests.get(f'https://www.instagram.com/{acc}/', headers={"User-Agent": "Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0"})

At my side, it worked and I got Status Code 200.

Wish you luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM