将 Qualtrics 的调查结果下载到 Python 中

问题描述 投票:0回答:1

我正在尝试直接将 Qualtrics 的数据响应直接获取到 pandas 数据框 python 中。有办法这样做吗?

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,
    }

然后#第1步:创建数据导出

downloadRequestUrl = baseUrl

然后当我尝试从我的 chrom 访问 url 时,它会给我以下内容

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

我相信运行此代码后的主要原因

# 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)

它给了我这个错误

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

我对 Qualtrics/python 界面不太熟悉,可能有人会分享为什么我遇到这个困难是因为数据中心吗?

谢谢你

python-3.x qualtrics
1个回答
0
投票

我知道 Stack 通常会对建议使用不同编程语言的回复不屑一顾,但考虑到 R 与 Python 的相似性以及这个问题在 3 年后仍未得到解决的事实,我想我应该分享一下我在 YouTube 上看到的东西视频。本质上,R 的 qualRics 包使这变得超级简单。


#Enter API info
qualtrics_api_credentials(api_key = "YOUR API KEY HERE", 
                          base_url = "yourdatacenterid.qualtrics.com/")

#This fetches a list of all of your surveys 
surveys <- all_surveys() 

#Set Time Zone
Sys.setenv(TZ = "UTC")

#Select survey to download
mysurvey <- fetch_survey(surveyID = "YOUR SURVEY ID HERE")

# Save responses to a CSV file
write.csv(mysurvey, file = "Demo_survey_responses.csv", row.names = FALSE)

Here’s the YouTube video for reference: [Qualtrics API and R][1]


  [1]: https://Mastering%20Qualtrics%20API%20&%20R:%20Automate%20Your%20Survey%20Data%20Like%20a%20Pro%20and%20Save%20Tons%20of%20Time%20and%20Work!%20https://youtu.be/eX7fH_wR-ws
© www.soinside.com 2019 - 2024. All rights reserved.