Answers: <p>As recommended by Jenkins (&gt;2.2xx) you may benefit by creating an API token for the user, I did so, to trigger Jenkins job in my local Jenkins server from NODEJS code.</p>
  <p>Please refer below for further clarification:</p>
  <ol>
  <li><a href="https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/#shell-with-curl" rel="nofollow noreferrer">https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/#shell-with-curl</a></li>
  <li><a href="https://www.jenkins.io/doc/book/using/remote-access-api/#RemoteaccessAPI-CSRFProtection" rel="nofollow noreferrer">https://www.jenkins.io/doc/book/using/remote-access-api/#RemoteaccessAPI-CSRFProtection</a></li>
  </ol>
  <p>And for details: <a href="https://www.jenkins.io/doc/book/managing/security/" rel="nofollow noreferrer">https://www.jenkins.io/doc/book/managing/security/</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2021-01-07T13:57:46.987Z
Answers: 2021-01-07T13:57:46.987Z
Answers: Vijaya M
Body: <p>I am trying to build a python script that will build jobs externally but when I am executing it, throws 403 forbidden error for build jobs call other get APIs are working fine. Below is the python snippet.</p>
  
  <pre><code>j=jenkins.Jenkins('http://localhost:8080/login?from=%2F', 'admin', 'admin@123' )
  
  j.get_jobs();
  
  print(j.jobs_count());
  
  print(j.get_jobs());
  
  j.build_job('demo1');
  </code></pre>
  
  <p>Jenkins details: I am able to create &amp; build jobs from UI successfully. My Jenkins version is 2.237.</p>
  
  <p>Other settings.</p>
  
  <ul>
  <li>logged in user can do anything. Csrf protection is disabled.
  On the other hand my friend having the same script and version of Jenkins is able to build job.</li>
  </ul>
  
Tags: <jenkins><python>
Title: 403 forbidden error on calling jenkins post api from python script
UserDisplayName: Nitish kumar
ThreadText: # 403 forbidden error on calling jenkins post api from python script
  
  (Asked by: username_0 on 2020-05-23)
  
  I am trying to build a python script that will build jobs externally but when I am executing it, throws 403 forbidden error for build jobs call other get APIs are working fine. Below is the python snippet.
  
  ```
  j=jenkins.Jenkins('http://localhost:8080/login?from=%2F', 'admin', 'admin@123' )
  
  j.get_jobs();
  
  print(j.jobs_count());
  
  print(j.get_jobs());
  
  j.build_job('demo1');
  
  ```
  
  Jenkins details: I am able to create & build jobs from UI successfully. My Jenkins version is 2.237.
  
  Other settings.
  
  * logged in user can do anything. Csrf protection is disabled.
    On the other hand my friend having the same script and version of Jenkins is able to build job.
  
  **Tags:** jenkins, python
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-07. Score: 1
  
  As recommended by Jenkins (>2.2xx) you may benefit by creating an API token for the user, I did so, to trigger Jenkins job in my local Jenkins server from NODEJS code.
  
  Please refer below for further clarification:
  
  1. <https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/#shell-with-curl>
  2. <https://www.jenkins.io/doc/book/using/remote-access-api/#RemoteaccessAPI-CSRFProtection>
  
  And for details: <https://www.jenkins.io/doc/book/managing/security/>
  
  
  ---
  
  