How to Run Python Script in Collabora Online deployed by default in Nextcloud AIO setup and fetch CSV data from API and save in excel sheet running inside the Nextcloud

There are a few things to check here:

  1. String literals: Replace the curly single quotes (, ) with straight single quotes (').
  2. Indentation: Ensure proper indentation for the code inside the try block and after the except block.
  3. Reading data from urllib response: The f.read() method returns bytes, which you need to decode to a string before setting it in a cell.
  4. Setting error messages: Convert the exception to a string before setting it in a cell.

Here is the corrected version of your script:

import uno
import urllib.request
document = XSCRIPTCONTEXT.getDocument()
url = 'https://somedomain?Div=Div1&month=April'

def write_something():
    month = "APRIL"
    div = "Div1"
    sheets = document.getSheets()
    firstSheet = sheets.getByIndex(0)
    firstSheet.getCellRangeByName("A1").setString('hhhhhh')
    firstSheet.getCellRangeByName("A4").setString('rrrrr')
    try:
        with urllib.request.urlopen(url) as f:
            data = f.read().decode('utf-8')  # Decode bytes to string
            print(data)  # Print the data for debugging
            firstSheet.getCellRangeByName("A2").setString(data)
        firstSheet.getCellRangeByName("A3").setString('aaaa')
        firstSheet.getCellRangeByName("A4").setString('bbbb')
    except urllib.error.URLError as e:
        firstSheet.getCellRangeByName("A4").setString(str(e))
    return None

Ensure the indentation is correct and matches the structure above. If you still do not see any logs or error messages, you might want to add more print statements to trace the execution flow and verify where the script might be failing. Additionally, check the container logs for any clues about potential issues not directly related to this script.

Thanks,
Darshan