Download survey results from Qualtrics into Python

痞子三分冷 提交于 2020-01-06 05:34:12

问题


I am trying to directly get the data responses from Qualtrics directly into a pandas dataframe python. Is there a way of doing so?

import shutil
import os
import requests
import zipfile
import json
import io

# Setting user Parameters
# apiToken = "myKey"
# surveyId = "mySurveyID"
# fileFormat = "csv"
# dataCenter = "az1" 

apiToken = "HfDjOn******"
surveyId = "SV_868******"
fileFormat = "csv"
dataCenter = 'uebs.eu'

# Setting static parameters
requestCheckProgress = 0
progressStatus = "in progress"
baseUrl = "https://{0}.qualtrics.com/API/v3/responseexports/".format(dataCenter)
headers = {
    "content-type": "application/json",
    "x-api-token": apiToken,
    }

Then for # Step 1: Creating Data Export

downloadRequestUrl = baseUrl

then when i try to access the url from my chrom it gives me the following

{"meta":{"httpStatus":"404 - Not Found","error":{"errorMessage":"The requested resource does not exist."}}}

Which I believe the main reason why after running this code

# Step 1: Creating Data Export
downloadRequestUrl = baseUrl
downloadRequestPayload = '{"format":"' + fileFormat + '","surveyId":"' + surveyId + '"}'
downloadRequestResponse = requests.request("POST", downloadRequestUrl, data=downloadRequestPayload, headers=headers)
progressId = downloadRequestResponse.json()["result"]["id"]
print(downloadRequestResponse.text)

It gives me this error

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-38-cd611e49879c> in <module>
      3 downloadRequestPayload = '{"format":"' + fileFormat + '","surveyId":"' + surveyId + '"}'
      4 downloadRequestResponse = requests.request("POST", downloadRequestUrl, data=downloadRequestPayload, headers=headers)
----> 5 progressId = downloadRequestResponse.json()["result"]["id"]
      6 print(downloadRequestResponse.text)

KeyError: 'result

I am somehow new to Qualtrics/python interface may someone share why I am having this difficulty is it because of the dataCenter?

Thank you

来源:https://stackoverflow.com/questions/59074289/download-survey-results-from-qualtrics-into-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!