title: Python3 error `IndexError: list index out of range`
body: <p>Hello all I am pretty new to python and trying to debug this error below. The script basically  creates a PAT (personal access token) on my Gitlab endpoint.</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/Test/test-gitlabtoken.py&quot;, line 86, in &lt;module&gt;
      main()
    File &quot;/Test/test-gitlabtoken.py&quot;, line 79, in main
      name = sys.argv[1]
  IndexError: list index out of range
  </code></pre>
  <p>Below is the full script I pulled from here --&gt; <a href="https://github.com/vitalyisaev2/gitlab_token/blob/main/personal_access_token.py" rel="nofollow noreferrer">https://github.com/vitalyisaev2/gitlab_token/blob/main/personal_access_token.py</a></p>
  <pre><code>#!/usr/bin/python3
  &quot;&quot;&quot;
  Script that creates Personal Access Token for Gitlab API;
  Tested with:
  - Gitlab Community Edition 10.1.4
  - Gitlab Enterprise Edition 12.6.2
  - Gitlab Enterprise Edition 13.4.4
  &quot;&quot;&quot;
  import sys
  import requests
  from urllib.parse import urljoin
  from bs4 import BeautifulSoup
  
  endpoint = &quot;https://blah.com&quot; # updated
  root_route = urljoin(endpoint, &quot;/&quot;)
  sign_in_route = urljoin(endpoint, &quot;/users/sign_in&quot;)
  pat_route = urljoin(endpoint, &quot;/-/profile/personal_access_tokens&quot;)
  
  login = &quot;root&quot;
  password = &quot;pass&quot; # updated
  
  
  def find_csrf_token(text):
      soup = BeautifulSoup(text, &quot;lxml&quot;)
      token = soup.find(attrs={&quot;name&quot;: &quot;csrf-token&quot;})
      param = soup.find(attrs={&quot;name&quot;: &quot;csrf-param&quot;})
      data = {param.get(&quot;content&quot;): token.get(&quot;content&quot;)}
      return data
  
  
  def obtain_csrf_token():
      r = requests.get(root_route)
      token = find_csrf_token(r.text)
      return token, r.cookies
  
  
  def obtain_authenticity_token(cookies):
      r = requests.get(pat_route, cookies=cookies)
      soup = BeautifulSoup(r.text, &quot;lxml&quot;)
      token = soup.find('input', attrs={'name': 'authenticity_token', 'type': 'hidden'}).get('value')
      return token
  
  
  def sign_in(csrf, cookies):
      data = {
          &quot;user[login]&quot;: login,
          &quot;user[password]&quot;: password,
          &quot;user[remember_me]&quot;: 0,
          &quot;utf8&quot;: &quot;✓&quot;
      }
      data.update(csrf)
      r = requests.post(sign_in_route, data=data, cookies=cookies)
      token = find_csrf_token(r.text)
      return token, r.history[0].cookies
  
  
  def obtain_personal_access_token(name, expires_at, csrf, cookies, authenticity_token):
      data = {
          &quot;personal_access_token[expires_at]&quot;: expires_at,
          &quot;personal_access_token[name]&quot;: name,
          &quot;personal_access_token[scopes][]&quot;: &quot;api&quot;,
          &quot;authenticity_token&quot;: authenticity_token,
          &quot;utf8&quot;: &quot;✓&quot;
      }
      data.update(csrf)
      r = requests.post(pat_route, data=data, cookies=cookies)
      soup = BeautifulSoup(r.text, &quot;lxml&quot;)
      token = soup.find('input', id='created-personal-access-token').get('value')
      return token
  
  
  def main():
      csrf1, cookies1 = obtain_csrf_token()
      print(&quot;root&quot;, csrf1, cookies1)
      csrf2, cookies2 = sign_in(csrf1, cookies1)
      print(&quot;sign_in&quot;, csrf2, cookies2)
      authenticity_token = obtain_authenticity_token(cookies2)
  
      name = sys.argv[1]
      expires_at = sys.argv[2]
      token = obtain_personal_access_token(name, expires_at, csrf2, cookies2, authenticity_token)
      print(token)
  
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>
  <p>My python version is <code>Python 3.9.7</code>
  I would appreciate any pointers. Thanks</p>