How to properly format Python list data when sending to Google Apps Script web app for Google Sheets integration

I’m trying to send data from a pandas DataFrame to a Google Apps Script web application, but I keep getting a 400 Bad Request error. Here’s my current Python setup:

import pandas as pd
import requests

user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
request_headers = {'User-Agent': user_agent}

data_frame = pd.DataFrame({
    'Numbers': [10, 20, 30, 40, 50],
    'Letters': ['X', 'Y', 'Z', 'W', 'V']
})
converted_list = data_frame.values.tolist()

target_url = 'https://example.com'
gas_endpoint = "https://script.google.com/macros/s/YOUR_ID/exec"

request_data = {
    'data_array': converted_list,
    'target_site': target_url
}

response = requests.get(
    gas_endpoint, 
    headers=request_headers, 
    params=request_data, 
    timeout=300
)

And here’s my Google Apps Script function:

function doGet(event) {
    var dataArray = event.parameter.data_array;
    var worksheet = SpreadsheetApp.getActive().getSheetByName('Python Data');
    worksheet.getRange(1, 1, dataArray.length, dataArray[0].length).setValues(dataArray);
}

I want the data to appear in my Google Sheet like this:

Numbers Letters
10 X
20 Y
30 Z
40 W
50 V

What’s the right way to format the list data so it gets processed correctly by the web app?

yeah, GET params stringify arrays automatically. use JSON.stringify() on your python list before sending it, or GAS won’t parse it correctly. on the GAS side, use JSON.parse() to convert the string back to an array if you’re sticking with GET.

The problem is you’re trying to send complex data through URL parameters with GET - that won’t work. Google Apps Script only gets URL parameters as strings, so your nested array gets completely messed up. Just switch to POST and send your data as JSON in the request body. Change your Python code to use requests.post() with json=request_data instead of params=request_data. On the Apps Script side, use doPost(event) and grab the data with JSON.parse(event.postData.contents) instead of event.parameter. I hit this exact issue last month sending DataFrame data to Sheets. GET can’t handle nested arrays like yours. Switch to POST with proper JSON and your data will flow through fine.