title: Login instagram using python
body: <p>I am having my own project to create a instagram bot. The first thin i need to do is to create a login. I created the below python script to login the instagram. However, it returns 403 status code to me. Anyone can give some advice on what's wrong? </p>
  
  <pre><code>import requests
  import json
  import random
  import time
  
  Base_url = 'https://www.instagram.com/'
  Login_url = 'https://www.instagram.com/accounts/login/'
  Username = 'username'
  Passowrd = 'password'
  User_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
  login_data = {'username': Username, 'password': Passowrd}
  
  session = requests.Session()
  session.headers.update({
              'Accept': '*/*',
              'Accept-Language': 'en-US,en;q=0.5',
              'Accept-Encoding': 'gzip, deflate, br',
              'Connection': 'keep-alive',
              'Content-Length': '0',
              'Host': 'www.instagram.com',
              'Origin': 'https://www.instagram.com',
              'Referer': 'https://www.instagram.com/',
              'User-Agent': User_agent,
              'X-Instagram-AJAX': '1',
              'Content-Type': 'application/x-www-form-urlencoded',
              'X-Requested-With': 'XMLHttpRequest'
          })
  
  req = session.get(Base_url)
  session.headers.update({'X-CSFRToken': req.cookies['csrftoken']})
  time.sleep(5 * random.random())
  
  login = session.post(Login_url, data=login_data, allow_redirects = True )
  session.headers.update({'X-CSFRToken': login.cookies['csrftoken']})
  csrftoken = login.cookies['csrftoken']
  #ig_vw=1536; ig_pr=1.25; ig_vh=772;  ig_or=landscape-primary;
  session.cookies['ig_vw'] = '1536'
  session.cookies['ig_pr'] = '1.25'
  session.cookies['ig_vh'] = '772'
  session.cookies['ig_or'] = 'landscape-primary'
  time.sleep(5 * random.random())
  print(login.status_code)
  
  if login.status_code == 200:
      #login_text_notjson = login.text
      print('sucessfully login')
  
      try:
          login_text = json.loads(login.text)
  
      except Exception:
          print('there is an error')
  
      else:
          #print(login_text_notjson)
          print(login_text)
  
  else: 
      print('you fail to login')
  </code></pre>
  
  <p>Very grateful if anyone can give me the information about creating a bot for that. I still have no idea why my user_agent didn't work for that.</p>