Python Forum
[split] script: remove all "carriage return" from my json variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] script: remove all "carriage return" from my json variable
#1
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))
         
Reply
#2
Search the forum
https://python-forum.io/Thread-script-re...n-variable
Reply
#3
If you are really sure it is just the carriage return at the end you could use lines[0].strip('\n') etc.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 1,913 Aug-13-2023, 12:16 AM
Last Post: cubangt
  Trouble with threading and reading variable from a different script Lembas 14 2,842 Apr-26-2023, 11:21 PM
Last Post: Lembas
  Python Script to convert Json to CSV file chvsnarayana 8 2,346 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  [split] Parse Nested JSON String in Python mmm07 4 1,428 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Remove a space between a string and variable in print sie 5 1,706 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Split string using variable found in a list japo85 2 1,238 Jul-11-2022, 08:52 AM
Last Post: japo85
  Python Split json into separate json based on node value CzarR 1 5,476 Jul-08-2022, 07:55 PM
Last Post: Larz60+
Question How can I import a variable from another script without executing it ThomasFab 12 7,560 May-06-2022, 03:21 PM
Last Post: bowlofred
  How to return the next page from json recursively? sandson 0 1,104 Apr-01-2022, 11:01 PM
Last Post: sandson
  [split] Help- converting file with pyton script eltomassito 6 3,192 Jul-02-2021, 05:29 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020