View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
19258 | Bug reports | RemoteControl | public | 2023-11-21 09:53 | 2023-11-28 16:29 |
Reporter | iceclimber81 | Assigned To | tibor.pacalat | ||
Priority | none | Severity | minor | ||
Status | closed | Resolution | fixed | ||
Product Version | 6.3.x | ||||
Summary | 19258: Update to 6.3.5 and later breaks limer / access via remotecontrol (issue 19214: change of JSON RPC response content type) | ||||
Description | The issue is described in the forum: https://forums.limesurvey.org/forum/installation-a-update-issues/127953-remotecontrol-doesn-t-work-after-update-to-php-8-1?start=12#252424 . DenisChenu recommended to report it here. Summary: The update from 6.3.4 to 6.3.5 and later contained fix of issue 19214 (JSON RPC response content type should be application/json (03610) --> see issue described here: bugs.limesurvey.org/view.php?id=19214). The JSON RPC response content type was changed from text/javascript to application/json. This seems to break the limer, specifically the get_session_key() function (https://github.com/cloudyr/limer/blob/master/R/get_session_key.R). We now get an error back: 500: Internal Server Error | ||||
Steps To Reproduce | Steps to reproduceIn R, executive the following code: r <- POST(getOption('lime_api'), content_type_json(), body = jsonlite::toJSON(body.json, auto_unbox = TRUE)) To check error message: Expected resultObtain a valid session key in the response object. Actual resultResponse object returns an error: | ||||
Tags | No tags attached. | ||||
Bug heat | 24 | ||||
Complete LimeSurvey version number (& build) | Works on 6.3.4+231108, breaks on 6.3.5 and 6.3.6 | ||||
I will donate to the project if issue is resolved | No | ||||
Browser | |||||
Database type & version | mysqlnd 8.2.9, 10.5.22-MariaDB | ||||
Server OS (if known) | Linux 5.4.0-164-generic | ||||
Webserver software & version (if known) | Apache | ||||
PHP Version | 8.2.9 | ||||
as I said on the forum, it seems to me that what is returned might not be JSON at all - just a 500 error page: original function is: If you execute it by parts:prepare POST requestbody.json = list(method = "get_session_key", that is OK and further gets a response from LSr <- POST(getOption('lime_api'), error then arises in the next step:session_key <- as.character(jsonlite::fromJSON(content(r, encoding="utf-8"))$result) if you look into what content of r is (btw it is library httr::content() function) you get html document:content(r, encoding="utf-8") if you look at the structure of r (seeing whole response):
|
|
I have just spend quite a while installing r and testing your issue. First problem i have is that your code makes no sense to me. Why are you sending a json request and then trying to decode XML? There are two RPC: json and xml. For json you send json, get back json. For xml you send xml, get back xml. Why are you trying to mix them? Second problem I have is that your code does not produce the result you say. I don't get any 500 error. I only see:
which makes sense because you try to decode json as xml my complete code: Load librarylibrary(limer) Setup API detailsoptions(lime_api = 'http://limesurvey-master-8_1/admin/remotecontrol') body.json = list(method = "get_session_key", r <- POST(getOption('lime_api'), content_type_json(), body = jsonlite::toJSON(body.json, auto_unbox = TRUE)) I don't use R much, so maybe I made a mistake, but I don't see your error. I just see correct json response with a valid session key. |
|
your steps to reproduce has a 500 error but your note has an r error with my testing I can only reproduce the r error and the r error is because you do not properly parse json |
|
Sorry, I realize I should have clarified that the 2 lines of code I signposted as “to check error message” may be faulty due to my inexperience with JSON. The R / liner error that is the actual problem is described earlier in the forum post: https://forums.limesurvey.org/forum/installation-a-update-issues/127953-remotecontrol-doesn-t-work-after-update-to-php-8-1?start=12#252424 The error occurs when wanting to get the session key as per limer documentation: Load librarylibrary(limer) Setup API detailsoptions(lime_api = 'http://example.com/limesurvey/admin/remotecontrol') Do stuff with LimeSurvey APIget_session_key() # Log in Error: |
|
Thanks for looking into this mfavetti. I think we may be getting confused by rvest and xml. The original code in getting session key is quite short and simple and relies on httr only (to make POST request) The actual function is pretty short
You can play it line by line and get the result I described above. jsonlite library cannot parse r that was returnedr should have been json
if you use |
|
idk what the difficulty is... library(limer) options(lime_api = 'http://limesurvey-master-8_1/admin/remotecontrol') body.json = list( r <- POST( body <- content(r, "text", encoding="utf-8") session_key <- as.character(json$result) print(session_key) yields |
|
i don't think its a problem with limesurvey i think its an issue with your r code parsing a json response |
|
oh i see the error if you use limer get_session_key() directly |
|
ok the problem is in limer if the response content type is application/json, httr automagically handles the conversion from json limer explicitly does the conversion (because limesurvey used to return a weird content type) so it's doing it twice now limer needs to update to remove jsonlite::fromJSON call |
|
or could specify type=text and continue manual json parsing |
|
i made a pr for limer to fix the issue for their redundant parsing, I think we can close this issue as it's not a limesurvey bug |
|
Amazing, thank you mfavetti for finding the solution so quickly! |
|
@mfavetti Are you sure this does not break for any Limesurvey before 6.3.5? See my remark on github / limer |
|
yeah I saw, I don't think it does before limesurvey had weird content type, so httr didn't do anything and limer parsed json now limesurvey has standard content type, so httr knows to parse json and limer parses json a second time, which causes error my pr just makes limer parse json of the response as text (so not parsed already by httr) which should handle both cases |
|
Thanks, mfavetti, very much for looking into it. The code we were posting is from Your code:
The official
But that really should not change anything, unless I am mistaken. You have other slight differences in the code and if I make a custom function |
|
OK, great, thanks @mfavetti for identifying the problem! Makes absolute sense and I did not spot the double conversion yet. |
|
I created a new fork with the PR by @mfavetti |
|
Thank you, @JanE and @mfavetti. I tested @JanE's fork with LS 6.3.4, 6.3.5 and 6.3.6. I confirm it works for all versions! Here is my R code: devtools::install_github("Jan-E/limer", force = TRUE) options(lime_api = 'my_remotecontrol_url') session_key <- get_session_key() # Log in |
|
Thanks everyone, I also confirm it works. PHP 7.4, LS CE 6.3.6. |
|
Updating to 5.6.45+ had the same effect, because the change to the application/json header has been backported. See the release notes: https://github.com/LimeSurvey/LimeSurvey/commit/a7f35a5c57cc8342c22173198a8dd42ef2cd550a |
|
Date Modified | Username | Field | Change |
---|---|---|---|
2023-11-21 09:53 | iceclimber81 | New Issue | |
2023-11-21 10:14 | r0bis | Issue Monitored: r0bis | |
2023-11-21 10:14 | r0bis | Bug heat | 0 => 2 |
2023-11-21 10:22 | r0bis | Note Added: 78561 | |
2023-11-21 10:22 | r0bis | Bug heat | 2 => 4 |
2023-11-21 10:42 | mfavetti | Note Added: 78563 | |
2023-11-21 10:42 | mfavetti | Bug heat | 4 => 6 |
2023-11-21 10:54 | mfavetti | Note Added: 78565 | |
2023-11-21 10:54 | DenisChenu | Relationship added | related to 19214 |
2023-11-21 11:06 | iceclimber81 | Note Added: 78566 | |
2023-11-21 11:06 | iceclimber81 | Bug heat | 6 => 8 |
2023-11-21 11:19 | r0bis | Note Added: 78569 | |
2023-11-21 11:22 | mfavetti | Note Added: 78570 | |
2023-11-21 11:25 | mfavetti | Note Added: 78571 | |
2023-11-21 11:30 | tibor.pacalat | Assigned To | => tibor.pacalat |
2023-11-21 11:30 | tibor.pacalat | Status | new => feedback |
2023-11-21 11:36 | guest | Bug heat | 8 => 14 |
2023-11-21 11:37 | mfavetti | Note Added: 78573 | |
2023-11-21 11:59 | mfavetti | Note Added: 78575 | |
2023-11-21 12:01 | mfavetti | Note Added: 78576 | |
2023-11-21 12:09 | mfavetti | Issue Monitored: mfavetti | |
2023-11-21 12:09 | mfavetti | Bug heat | 14 => 16 |
2023-11-21 12:10 | mfavetti | Note Edited: 78575 | |
2023-11-21 12:11 | mfavetti | Note Edited: 78576 | |
2023-11-21 12:18 | mfavetti | Note Added: 78580 | |
2023-11-21 12:21 | mfavetti | Note Edited: 78580 | |
2023-11-21 12:24 | iceclimber81 | Note Added: 78583 | |
2023-11-21 12:24 | iceclimber81 | Status | feedback => assigned |
2023-11-21 12:45 | JanE | Note Added: 78584 | |
2023-11-21 12:45 | JanE | Bug heat | 16 => 18 |
2023-11-21 12:47 | mfavetti | Note Added: 78585 | |
2023-11-21 12:58 | r0bis | Note Added: 78586 | |
2023-11-21 13:01 | r0bis | Note Added: 78587 | |
2023-11-21 13:08 | JanE | Note Added: 78588 | |
2023-11-21 13:42 | iceclimber81 | Note Added: 78589 | |
2023-11-21 14:12 | r0bis | Note Added: 78590 | |
2023-11-28 11:02 | JanE | Note Added: 78765 | |
2023-11-28 16:29 | tibor.pacalat | Status | assigned => closed |
2023-11-28 16:29 | tibor.pacalat | Resolution | open => fixed |
2023-11-28 16:36 | tibor.pacalat | Bug heat | 18 => 24 |