title: GET Access token from API (oauth2)
body: <p>I am very beginner at Python scripting and i have a problem.</p>
  
  <p>I am trying to rewrite PHP code to Python to get Access token from API for further use.</p>
  
  <pre><code>##/* Request for access token */
  
  $base_url = "myurl";
  $client_id="1234";
  $client_secret="5678";
  
  $client_details = "${client_id}:${client_secret}";
  
  $context = stream_context_create(array(
      'http' =&gt; array(
      'method' =&gt; 'POST',
      'header' =&gt; "Content-Type: application/x-www-form-urlencoded\r\n" .
                  "Authorization : Basic $client_details\r\n",
      'content' =&gt; "grant_type=client_credentials"
      )
  ));
  
  $response = file_get_contents($base_url.'/apis/oauth2/Token.php', false, $context);
  $res =  json_decode($response);
  $token = $res-&gt;access_token;
  </code></pre>
  
  <p>This is what i am trying to do in Python.</p>
  
  <p>My Python code is:</p>
  
  <pre><code>import urllib
  import sys
  import json
  import requests
  
  base_url = 'myurl'
  client_id='1234'
  client_secret='5678'
  
  response = requests.post(base_url+'/apis/oauth2/Token.php',
                      auth=(client_id, client_secret))
  
  print(response.json())
  </code></pre>
  
  <p>but this is not working</p>
  
  <p>Python is returning:</p>
  
  <pre><code>{'error': 'invalid_request', 'error_description': 'The grant type was not specified in the request'}
  </code></pre>
  
  <p>I know that i am missing everything from the context variable from PHP Code. Do you know if there is a python method to create context like stream_context_create in PHP or maybe could you give me some tips how can i do it?</p>