I tried the old request URL in the code, but it did not work:
response = requests.get(f"https://www.instagram.com/api/v1/users/web_profile_info/?username={username}", headers=header)
Any other way to get the user details, especially to check if the user is private or public
Instagram will attempt to block you if you don't use a matching User-Agent header. Although not perfect, and will probably get you IP-banned pretty quickly, this is a fix which works: