pythonjsonjenkinspython-requestsjenkins-api

How to solve the JSON Decode Error that occurs only in Jenkins?


I am trying to run a python code on Jenkins which is located on the remote server. The code runs fine in my local jenkins as well as command prompt. It also runs correctly on the command prompt of the remote machine but fails while running on Jenkins. I get Json decode error while running on Jenkins. I tried running through build steps - Execute Python Script, Execute Windows Batch Command, Execute Shell.

import requests
import json
import csv
import os
from datetime import datetime
import pandas as pd
url = 'http://xx.xx.xx.xx:8080/view/view_name/api/json'   #change the view name here
user = 'username'
pwd = 'password'
r = requests.get(url, auth=(user, pwd))
j = r.json()
print(j)

Error: Text]([![Error that I am getting on Jenkins]1


Solution

  • The code doesnt have any problem as it works fine in other jenkins and command prompt. The issue was, in the url, I was giving the ip address of the machine on which jenkins was installed. After I gave localhost:8080 insted of ip address the issue got resolved.