Really excited about the latest Python API update. Would like to be able to export survey responses as reports with Python. I'm currently stuck at this part. I can see that the reports get generated and I can download them (image below from Survey123 website), but I receive an error in the code: KeyError: 'results' (see attachment). I'm also curious if you can access the generated reports directly with Python after making them.
Solved! Go to Solution.
Hi
This is really helpful thank you for sharing I'm trying to hopefully use this for our workflow but I keep running into this error maybe someone can help. I made sure to download the other python libraries but looking at the docx.py I'm not sure what's going on. Any help is much appreciated
Hi Kassandra, I think this could be related to your version of the docx library?
For Python 3.x, you need the python-docx library rather than docx.
These links have more info: https://pypi.org/project/python-docx/
Try uninstalling the old one, install python-docx, then see how that goes.
Hi John, That was it thank you for your help
Hi Kassandra,
Could you share how you are importing the python-docx module. I keep getting an error in my script saying.
import python-docx
File "<ipython-input-6-d71ba5c26d0b>", line 1
import python-docx
^
SyntaxError: invalid syntax
Cheers,
Simon
My problem was that I was using the wrong version of python which was 2.7, so I still used:
import docx
but I think your asking how to install the library? This video should help with that Install Python with Matplotlib, Numpy+MKL, and SciPy - YouTube you would just replace it with
pip install python-docx
let me know if that answers your question
Hi Kassandra,
I am using PyCharms IDE with a python virtual environment. When adding python-docx from pipy repository I am getting a invalid ssl certificate error. I think this is an issue with my internal firewall so I have contacted my it department. I tried adding a ssl certificate to list of those trusted in pycharms but that hasn’t worked either. Strange tho that I was able to upgrade the pip and requests modules but not able to add python-docx?
Thanks,
Simon Allard
GIS Analyst
Bay of Plenty Regional Council Toi Moana
I had tried all sorts of things but in the end it was the firewall on our corporate network! We finally got it sorted though and I am working through the script to generate reports. I am having a bit of trouble with a couple lines of code - one is specifying the "where" filter variable and applying this in the 'generate reports module'
where_filter = '{"where":"CreationDate >= CURRENT_TIMESTAMP - INTERVAL \'1\' DAY"}'
survey.generate_report(template, where_filter, utc_offset, report_title)
The script runs but doesn't return any surveys. I have only succeeded when use 1=1 which returns all reports!
I tested the sql query:
which returned results but only when the sql format was set to standard from none.
Any thoughts?
Thanks,
Simon
Hi Simon sorry I can't help with this, we ended up going with the out of the box feature reports. I'd ask John Stowell for further help
Hi John,
I'm using your script and I'm getting this error, do you know why?
I installed smtplib, python-docx, and glob but I'm still getting this error. Is it my firewall giving me problems?
I might need to download to a folder.