TaiSHiNet/lime-py-api

limesurvey.py

Closed this issue · 13 comments

Error when running limesurvey.py from import

Error:

Traceback (most recent call last):
File "example.py", line 13, in
lime = Api(url, user, key)
File "/Users/user/Documents/python/lime-py-api/limesurvey.py", line 21, in init
self.session_key = self._getJSON(data)['result']
TypeError: 'NoneType' object has no attribute 'getitem'

That's odd, care to share you configuration (you can exclude your keys)?

not sure which configurations you mean, trying to run the example.py with configurations in config.py changed to my domain etc.

LIME_USER = 'username'
LIME_KEY = 'pw'
LIME_API_URL = 'http://www.domain.com/limesurvey/admin/remotecontrol'
LIME_TOKEN_BASE = 'token'
LIME_SID = 'my_sid'

haven't looked very much into the API but is it possible to export token table for a survey and not specific answers from tokens only?

@gurkanboll : the last comment must be in limesurvey system, not here. And
@TaiSHiNet : myave adding some control on self.getJSON(data) ? 500 error can happen :)

@Shnoulle that's what I thought. Anyways, would be nice to add token export for surveys.

@TaiSHiNet do you have any conifg/example for reproduction? Still cant get the "TypeError: 'NoneType' object has no attribute 'getitem'" to work out. Another question, what does LIME_TOKEN_BASE = 'token' in the config exactly do?

Been overflowed with work. This is my example config (with previous commented lines and stuff)

#!/usr/bin/python

from limesurvey import Api
import base64  # para encodear la subida de surveys
import config
import json

# Variable definition
user = config.LIME_USER
key = config.LIME_KEY
url = config.LIME_API_URL
sid = config.LIME_SID

# Build the API
lime = Api(url, user, key)

# Obtain questions
# for g in lime.list_groups(sid):
#     print('Grupo:', g[0])
#     print('Título:', g[1])
# for i in lime.export_responses(sid):
#   print(i)
res = lime.export_responses(sid)
# res = res.decode('utf-8')
#
# ser = json.loads(res)
# res = lime.get_survey_properties(sid)
print(res)
lime.release_session_key()

Oh and ignore spanish comments :P (most likely they're not mine)

it's cool, im just glad there's someone out there who had put this api together.. but still gives me the error when building the api, you're running the Api class as stated in limesurvey.py?

class Api:
def init(self, url, user, key):
self.url = url
self._user = user
self._password = key

    data = """{   "id": 1,
                "method": "get_session_key",
                "params": { "username": "%s",
                            "password": "%s" } } """ % (user, key)
    self.session_key = self._getJSON(data)['result']

i have tried using both local installed limesurvey, the demo online version and one online on a server without sucess..

As @Shnoulle said, could be a 500 coming from your Lime, try to dismember the request and perform it manually through curl

Thanks for your reply. After some troubleshooting I got it to work, i am not sure but it seems like json module somehow didn't work for me, but json should come along with python and is not a external module right? anyhow, installing json-rpc did the trick.

@gurkanboll Awesome, great to know, let me know if you have any feature request and I'll try to get it!

@TaiSHiNet ye it's a really handy api, thanks. I'll create a 'pull request' (im new on github so im still figuring out how everything works) because the list_survey does not work, at least not for me, so I updated it.
I also added the function list_participants(), but I need to figure out how to return the FULL token table and not only parts of it, as it is now it only returns 'tid', 'firstname', 'lastname', 'email' and 'token' whereas I want it to return the full table along with attributes, 'usesleft', 'completed' etc. And it could probably be done with some neater code where 'iLimit' isn't set to like 100000 as it is now.