Bottom Page

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))
         

Quote
#2
Search the forum
https://python-forum.io/Thread-script-re...n-variable
Quote
#3
If you are really sure it is just the carriage return at the end you could use lines[0].strip('\n') etc.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [split] Creating a variable as a function DPaul 23 538 Sep-07-2020, 05:20 PM
Last Post: DPaul
  Getting Shell to take prompt string plus int value and carriage return bayouprophet 1 133 Aug-29-2020, 05:13 PM
Last Post: bowlofred
  Function will not return variable that I think is defined Oldman45 6 295 Aug-18-2020, 08:50 PM
Last Post: deanhystad
  Use dynamic variable from parallel running python script Sicksym 0 221 May-15-2020, 02:52 PM
Last Post: Sicksym
  Using variable from a class in another .py script keegan_010 4 293 Mar-25-2020, 07:47 AM
Last Post: keegan_010
  How to Save Full Email Body to CLOB in Oracle w/Carriage Returns? bmccollum 1 431 Mar-12-2020, 10:25 PM
Last Post: Larz60+
  Regex to retrieve data from json in script tag. DreamingInsanity 4 1,907 Dec-20-2019, 06:18 PM
Last Post: DreamingInsanity
  Split of key from JSON response aswini_dubey 1 434 Dec-04-2019, 06:54 PM
Last Post: Larz60+
  [split] Print JSON Dictionary to Excel? venukommu 1 472 Nov-15-2019, 09:33 PM
Last Post: micseydel
  Pyautogui script runs fine if split into two parts together it does not Bmart6969 1 564 Oct-07-2019, 10:53 PM
Last Post: Bmart6969

Forum Jump:


Users browsing this thread: 1 Guest(s)