Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when get _responses #30

Open
gitbobo opened this issue May 23, 2017 · 16 comments
Open

error when get _responses #30

gitbobo opened this issue May 23, 2017 · 16 comments

Comments

@gitbobo
Copy link

gitbobo commented May 23, 2017

get_session_key()
[1] "ddrvaxfczqv9i5bhf4h34ukq5h86f4jt"
responses <- get_responses(913762)
Error in make.names(col.names, unique = TRUE) :
invalid multibyte string 1

could you pls tell me what's the problem may be, thanks!

@r0berts
Copy link

r0berts commented Jun 20, 2018

I got the same error and then I looked at survey permissions - turned out that the user did not have survey permissions, once I added them I got data. Strange thing however was that I got all fields in one column. Troubleshooting that now.

@Jan-E
Copy link
Contributor

Jan-E commented Jun 20, 2018

@r0berts

Strange thing however was that I got all fields in one column. Troubleshooting that now.

Could that be related to d7c0c3e ?

@r0berts
Copy link

r0berts commented Jun 20, 2018

@Jan-E That is right - it was. It is because I had an older version (Version 2.67.1+170626) where the field separator was different. I solved this by installing a version pre-29th April. install_github("cloudyr/limer", ref = "f0e2acced9178133f56f09f40ba690d6787eda64") - I will update the installation some time soon, but presently I just needed the exporting to work.

@Jan-E
Copy link
Contributor

Jan-E commented Jun 20, 2018

@r0berts We had it the other way around. Limesurvey 3.12.1, but a limer that was too old. So we just had to update limer. I will see if I can patch it do do a version-specific base64_to_df.

@Jan-E
Copy link
Contributor

Jan-E commented Jun 20, 2018

The PR seems to be already there: #42

@r0berts
Copy link

r0berts commented Jun 20, 2018

@Jan-E this is good, perhaps to have an option to supply version or other switch. If need be, I could do some work on documenting limer, so that it would be easier for newcomers to figure this out. I could do something like a manpage from a begginner's viewpoint, if you'd like - maybe to supplement the readme file?

@Jan-E
Copy link
Contributor

Jan-E commented Jun 20, 2018

I am already experimenting to get the version number:

get_session_key()
lsversion<-call_limer(method="get_site_settings",params=list(sSetttingName="versionnumber"))
lsmajor<-substr(lsversion, 1, 1)
print(lsmajor)

In my case lsversion becomes "3.12.1" and lsmajor "3". With this it should be possible to restrict d7c0c3e to versions > 2.

@Jan-E
Copy link
Contributor

Jan-E commented Jun 20, 2018

@r0berts Could you test
devtools::install_github("toolsforresearch/limer", username = NULL, ref = "ls_v2_export_responses")

3b1d2d1 handles LS v2 the old way and LS v3 with a sep = ";". I tested it for Limesurvey 3.12.1.

Can you confirm it works in LS v2? Then I will create e new Pull Request.

@r0berts
Copy link

r0berts commented Jun 21, 2018

@Jan-E It seems NOT to work. There are error messages:

Error in if (lsmajor < 3) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In base64_to_df(unlist(results)) : NAs introduced by coercion

And no data are received.
When I quit the session (restart rstudio) and run (knitr) the report it does not work at library loading stage:

Quitting from lines 13-50 (surveyProc.rmd) 
Error in if (lsmajor < 3) { : missing value where TRUE/FALSE needed
Calls: <Anonymous> ... withVisible -> eval -> eval -> get_responses -> base64_to_df
In addition: Warning message:
In block_exec(params) : failed to tidy R code in chunk <setup>
reason: Error in loadNamespace(name) : there is no package called 'formatR'

But when I load libraries manually I do not seem to get that error on loading, but later no data received with the first error.

@Jan-E
Copy link
Contributor

Jan-E commented Jun 21, 2018

Looks like lsmajor is not set. Could you run this in a R prompt, after entering your lime_api options:

library(limer)
get_session_key()
lsversion<-call_limer(method="get_site_settings",params=list(sSetttingName="versionnumber"))
print(lsversion)
lsmajor<-as.numeric(substr(lsversion, 1, 1))
print(lsmajor)

@r0berts
Copy link

r0berts commented Jun 21, 2018

@Jan-E Yes, lsmajor is returned as list with this content:

> str(lsversion)
List of 1
 $ status: chr "Invalid setting"

Maybe it is due to this - from API reference:
Get a global setting
get_site_settings(string $sSessionKey, string $sSetttingName) : string|array
Function to query site settings. Can only be used by super administrators.
As I connect from a plain user account. - Yess that is it. If I substitute my superuser account the version string reported correctly. I am not sure RPC use plaintext or ssl in connecting to limesurvey, but I really liked to use a non-privileged account. I am giving report capability to plain users and I would not want to give s-admin password to them. Maybe a simple solution is to add an extra option like:

options(lime_api = limeAPI)
options(lime_username = "user1")
options(lime_version = "2")

It could by default be set to 3 and it could also have the automatic checking running alongside - in case it is run from super-admin account.

@Jan-E
Copy link
Contributor

Jan-E commented Jul 26, 2018

@r0berts
Ouch. We also had a script with LS 2 and a non-superadmin RPC2 user. Hence, it failed. I now tried another method: test if 'copy_survey' exists. copy_survey was introduced in LS 3.0.

toolsforresearch@d92be6f?diff=unified contains the final function:

base64_to_df <- function(x) {
  raw_csv <- rawToChar(base64enc::base64decode(x))

  have_copy_survey <- call_limer(method="copy_survey")
  # returns NULL in LS2
  # returns array(status => "Copy failed", error => "No survey ID has been provided. Cannot copy survey") in LS3
  if (is.null(have_copy_survey)) {
    return(read.csv(textConnection(raw_csv), stringsAsFactors = FALSE))
  } else {
    return(read.csv(textConnection(raw_csv), stringsAsFactors = FALSE, sep = ";"))
  }
}

I confirmed that this works in LS Version 2.6.4-lts with a non-superadmin account. Could you once again test the patch?

devtools::install_github("toolsforresearch/limer", username = NULL, ref = "ls_v2_export_responses_version_2")

Thanks.

@tammoterhark
Copy link

@Jan-E:

get_session_key()
lsversion<-call_limer(method="get_site_settings",params=list(sSetttingName="versionnumber"))
lsmajor<-substr(lsversion, 1, 1)
print(lsmajor)

Isn't there one "t" too many in SettingName? ;-)

@Jan-E
Copy link
Contributor

Jan-E commented Jul 27, 2018

Yes, but they are quite convinced, that you spell it that way
https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/remotecontrol/remotecontrol_handle.php#L95

@r0berts
Copy link

r0berts commented Aug 2, 2018

@Jan-E

Hi Jan, sorry I was away. I tested today. Your version works fine on my 2.67 - it gets data perfectly alright with non admin account. Then I tested it on the latest version of LS (Version 3.14.1+180731) running on my laptop - it fails with this error:

 > initData <- get_responses(limeSurveyNumber)  
Error: lexical error: invalid char in json text.  
                                       <!DOCTYPE html> <html lang="en"  
                     (right here) ------

I also tested the latest limesurvey version with the version from standard repo https://github.com/cloudyr/limer and that works fine on the latest.

@tammoterhark
Copy link

@Jan-E Would it be an idea to have two versions of this piece of software: limer and limer3, to avoid this confusion.

And to persuade the LS developers to make it possible to ask the API for a version number?

Using LS3.14 I ran into this problem again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants