# 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

**URL:** <https://forum.collaboraonline.com/t/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/2832>\
**Category:** Installation & Configuration\
**Created:** [August 3, 2024, 5:39pm UTC](https://forum.collaboraonline.com/t/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/2832 "2024-08-03T17:39:48Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![darshan](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.collaboraonline.com/darshan/32/2230_2.png) [@darshan](https://forum.collaboraonline.com/u/darshan)\
**Post date:** [August 8, 2024, 4:41am UTC](https://forum.collaboraonline.com/t/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/2832/5 "2024-08-08T04:41:39Z")

</div>

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:

```python
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

---

_[View the full topic](https://forum.collaboraonline.com/t/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/2832)._
