title: run python in javascript
body: <p>I have a python script <code>python.py</code> as follow:</p>
  
  <pre><code>import requests
  import json
  
  url = "https://api.dropboxapi.com/2/sharing/list_shared_links"
  
  headers = {
      "Authorization": "Bearer MY_ACCESS_KEY",
      "Content-Type": "application/json"
  }
  
  data = {
      "path": "/downloads/files.txt"
  }
  
  r = requests.post(url, headers=headers, data=json.dumps(data))
  </code></pre>
  
  <p>and a php web page as follow:</p>
  
  <pre><code>&lt;html&gt;
      &lt;script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'&gt;&lt;/script&gt;
  
          &lt;button id="getlink"&gt;Get Link&lt;/button&gt;
          &lt;div id="output"&gt;&lt;/div&gt;
  &lt;script&gt;
          function handleSharedLink(evt) {
               exec(python getLink.py);
          }
  
          var obj = document.getElementById('getlink').addEventListener('click', handleSharedLink, false);
          document.getElementById('output').innerHTML = obj;
  &lt;/script&gt;
  </code></pre>
  
  <p>Btw, I couldn't get the result from the python and show in the html <code>div&lt;'output'&gt;</code>. 
  How can I show that? Any help will be appreciated!</p>
  
  <p><strong>EDITED:</strong>
  I edited my code as follow instead of running the python file in the javascript. But the result still doesn't show.</p>
  
  <pre><code>&lt;html&gt;
  &lt;script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'&gt;&lt;/script&gt;
  
  &lt;input type="file" id="files" name="files[]" multiple /&gt;
  &lt;br/&gt;&lt;br/&gt;
  
  &lt;button id="getlink"&gt;Get Link&lt;/button&gt;
  &lt;div id="output"&gt;&lt;/div&gt;
  
  &lt;script&gt;
   function handleSharedLink(evt) {
  
    $.ajax({     
       url: "https://api.dropboxapi.com/2/sharing/get_shared_links",
  
       headers:
          {
              "Authorization": "Bearer 1lzp0Ii5agAAAAAAAAAAJTVD-jRpVMcOfefVBzVkXOzM-W_LiFHSl7F9mgkd4bYk",
              "Content-Type": "application/json"
          },
  
      data:
          {
              "path": "TARCpace.apk"
          },
      success: function (data) {
              console.log(data);
      },
      error: function (data) {
              console.log(data);
      }
      r = requests.post(url, headers=headers, data=json.dumps(data))       
   })
  }
  
    var output = document.getElementById('getlink').addEventListener('click', handleSharedLink, false);
    output.innerHTML = html(r);
  &lt;/script&gt;
  
  &lt;/html&gt; 
  </code></pre>
  
  <p>How can I improve that?</p>