Storing information on external files


I’m a student working on farmbot as a semester project. The idea was to divide the plot of the farmbot up and have different regions according to plant-growth stages. In this context, I wanted to store information about each of these regions and plant emplacements in an xml file.

However, It seems as if it’s impossible to use etree in the farmbot context. Is that so? And if so, is there a work-around?

I was also planning on using pickler to easily be able to store objects, but I think that doesn’t work either does it?

Thanks in advance for any help,


Both are available as modules to Farmware, as they are part of the Python standard library:

import pickle
import xml.etree.ElementTree


I do import both of them, but it gives me an error, immediately on the first call of xml.etree.ElementTree in the code. I’ve run it in shell on Ubuntu in debug mode and there it works perfectly.
Is there a specific way to import the modules or to pip them onto the bot?


What is the error, and which version of Python are you using on Ubuntu?


In Ubuntu, there is no error and the WebApp just gives me “Farmware execution failed”.

I am using Python 3.6.7 on Ubuntu 18.04.


Farmware currently only supports Python 2.7. I imagine the code you’ve written uses Python 3 features which are causing errors when run with Python 2.


I’ve now tested with python 2.7 (that was pretty stupid of me actually, using python 3.5). The error seems to have been that I was using the requests module, which doesn’t work in python 2.7. I haven’t tested with the robot yet, but I’m optimistic :smiley: I’ve now changed to urllib2.

I’ll give an update on how it went when I’ve tried on the robot.

Thanks for all the help!


We hope to switch to Python 3 at some point, but are on Python 2 for now.

The requests module is currently available for use:

import requests


Ok, so I changed back because urllib doesn’t work and since you told me that requests does in fact work.

The problem is, that it still gets caught on the xml parse part…

e = xml.etree.ElementTree.parse('./plantTypes.xml').getroot()

def initPlantTypes(self):
    log("Present.", message_type='info')
    e = xml.etree.ElementTree.parse('./plantTypes.xml').getroot()
    log("Accessed plantTypes.xml", message_type='info')
    for plantType in e:
        name = plantType.attrib["name"]
        lightNeeded = int(plantType.attrib["lightNeeded"])
        gt0 = int(plantType.attrib["gt0"])
        gt1 = int(plantType.attrib["gt1"])        
        gt2 = int(plantType.attrib["gt2"])     
        self.plantTypeList.append(PlantType(name, lightNeeded, gt0, gt1, gt2))
    log("Loaded plant types.", message_type='info')

This is the function that is giving an error. It logs “Present”, but never logs “Accessed plant types.”
I’m at a loss. Is there a blatantly stupid error somewhere in there?

(Btw there is no path error. I triple checked it. The file does exist and is filled with xml, which on the computer is parsed perfectly.) (With python 2.7 this time)


For debugging purposes you could try catching the error:

    e = xml.etree.ElementTree.parse('')
except Exception as error:


Thx, I will try that tomorrow, as I don’t have access to the robot right now. I will give an update on how it went.