Python Forum

Full Version: [split] script: remove all "carriage return" from my json variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am doing a get request for the api call to verify the values but I am having assert error due to white space \n which is in the json api call. How to handle this? I tired everything possible to replace and string command.

with open(“file.csv", "r") as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        next(csv_reader)
        for lines in csv_reader:
            indi = lines[0]
            resource_type = lines[1]
            source = lines[3]
            name = lines[4]
           
            response = requests.get(
                'https://api.somewebsite + indi).json()
            pp = pprint.PrettyPrinter(indent=4)
            pp.pprint(json.dumps(response,indent=4))
         
If you are really sure it is just the carriage return at the end you could use lines[0].strip('\n') etc.