Select to view content in your preferred language

Generate Survey123 Report

11178
35
Jump to solution
11-28-2018 09:56 AM
ChelseaRozek
MVP Regular Contributor

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.

0 Kudos
35 Replies
KassandraRodriguez
Frequent Contributor

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

0 Kudos
JohnStowell
Regular Contributor

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/

https://stackoverflow.com/questions/22765313/when-import-docx-in-python3-3-i-have-error-importerror-...

Try uninstalling the old one, install python-docx, then see how that goes.

KassandraRodriguez
Frequent Contributor

Hi John, That was it thank you for your help

SimonAllard2
Regular Contributor

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

0 Kudos
KassandraRodriguez
Frequent Contributor

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

0 Kudos
SimonAllard2
Regular Contributor

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

0 Kudos
SimonAllard2
Regular Contributor

Hi Kassandra Rodriguez,

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

0 Kudos
KassandraRodriguez
Frequent Contributor

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 

0 Kudos
MichelleWilliams1
Frequent Contributor

Hi John,

I'm using your script and I'm getting this error, do you know why?

0 Kudos
MichelleWilliams1
Frequent Contributor

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.

0 Kudos