Repository: oppia/oppia

Issue:
"Error communicating with server" prompt appears while scrolling down on explorations of a category.
![screenshot from 2016-06-24 16 02 32](https://cloud.githubusercontent.com/assets/11073943/16335595/209c18ac-3a25-11e6-844c-86669f6e53e7.png)

**How To Reproduce:**
- Visit https://www.oppia.org
- Click on any category name (example: Mathematics & Statistics) and scroll down.

**Observed Behavior:**
"Error communicating with server" prompt appears while scrolling down on explorations of a category.



Discussion:
Hi @abhsag24, would you be interested in investigating what's causing this? 

okay i'll try :)

Thanks! Assigned you.

Btw, some tips I've found helpful for simulating stuff like this on the dev server is to do the following:
- Log in as an admin, go to /admin, and click "Reload all explorations" to load a bunch of explorations in the library.
- In the backend, find the constant that determines the number of things to show in a "search results page", and change it to 8. If you make the height of your browser window smaller, this will allow you to simulate the "scroll down and fetch more" action.

Hope these are useful!

thanks :D


Resolving patch:
diff --git a/core/controllers/editor.py b/core/controllers/editor.py
--- a/core/controllers/editor.py
+++ b/core/controllers/editor.py
@@ -18,7 +18,6 @@
 
 import datetime
 import imghdr
-import json
 import logging
 
 import jinja2
@@ -699,11 +698,11 @@ class StateYamlHandler(EditorHandler):
     layer.
     """
 
-    def get(self):
-        """Handles GET requests."""
+    def post(self):
+        """Handles POST requests."""
         try:
-            state_dict = json.loads(self.request.get('stringified_state'))
-            width = json.loads(self.request.get('stringified_width'))
+            state_dict = self.payload.get('state_dict')
+            width = self.payload.get('width')
         except Exception:
             raise self.PageNotFoundException
 
diff --git a/core/controllers/library.py b/core/controllers/library.py
--- a/core/controllers/library.py
+++ b/core/controllers/library.py
@@ -34,11 +34,18 @@
 
 def get_matching_activity_dicts(query_string, search_cursor):
     """Given a query string and a search cursor, returns a list of activity
-       dicts that satisfy the search query.
+    dicts that satisfy the search query.
     """
-    collection_ids, search_cursor = (
-        collection_services.get_collection_ids_matching_query(
-            query_string, cursor=search_cursor))
+    # We only populate collections in the initial load, since the current
+    # frontend search infrastructure is set up to only deal with one search
+    # cursor at a time.
+    # TODO(sll): Remove this special casing.
+    collection_ids = []
+    if not search_cursor:
+        collection_ids, _ = (
+            collection_services.get_collection_ids_matching_query(
+                query_string))
+
     exp_ids, new_search_cursor = (
         exp_services.get_exploration_ids_matching_query(
             query_string, cursor=search_cursor))


Test patch:
diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py
--- a/core/controllers/editor_test.py
+++ b/core/controllers/editor_test.py
@@ -15,7 +15,6 @@
 """Tests for the exploration editor page."""
 
 import datetime
-import json
 import os
 import StringIO
 import zipfile
@@ -614,11 +613,14 @@ def test_state_yaml_handler(self):
         exploration.add_states(['State A', 'State 2', 'State 3'])
         exploration.states['State A'].update_interaction_id('TextInput')
 
-        download_url = (
-            '/createhandler/state_yaml?'
-            'stringified_state=%s&stringified_width=50' %
-            json.dumps(exploration.states['State A'].to_dict()))
-        response = self.get_json(download_url)
+
+        response = self.testapp.get(
+            '%s/%s' % (feconf.EDITOR_URL_PREFIX, exp_id))
+        csrf_token = self.get_csrf_token_from_response(response)
+        response = self.post_json('/createhandler/state_yaml', {
+            'state_dict': exploration.states['State A'].to_dict(),
+            'width': 50,
+        }, csrf_token=csrf_token)
         self.assertEqual({
             'yaml': self.SAMPLE_STATE_STRING
         }, response)
diff --git a/core/tests/protractor/editorAndPlayer.js b/core/tests/protractor/editorAndPlayer.js
--- a/core/tests/protractor/editorAndPlayer.js
+++ b/core/tests/protractor/editorAndPlayer.js
@@ -112,15 +112,15 @@ describe('Full exploration editor', function() {
       editor.setObjective('do some stuff here');
       expect(browser.getCurrentUrl()).toEqual(
         general.SERVER_URL_PREFIX + general.EDITOR_URL_SLICE + explorationId +
-        '?new#/gui/second');
+        '#/gui/second');
       browser.navigate().back();
       expect(browser.getCurrentUrl()).toEqual(
         general.SERVER_URL_PREFIX + general.EDITOR_URL_SLICE + explorationId +
-        '?new#/settings');
+        '#/settings');
       browser.navigate().back();
       expect(browser.getCurrentUrl()).toEqual(
         general.SERVER_URL_PREFIX + general.EDITOR_URL_SLICE + explorationId +
-        '?new#/gui/second');
+        '#/gui/second');
 
       // Check display of content & interaction in the editor
       editor.setContent(function(richTextEditor) {
diff --git a/core/tests/protractor/i18n.js b/core/tests/protractor/i18n.js
--- a/core/tests/protractor/i18n.js
+++ b/core/tests/protractor/i18n.js
@@ -33,19 +33,19 @@ var _selectLanguage = function(language) {
 describe('Site language', function() {
   beforeEach(function() {
     // Starting language is English
-    browser.get('/splash');
+    browser.get('/about');
     _selectLanguage('English');
-    expect(browser.getTitle()).toEqual('Oppia: Teach, Learn, Explore');
+    expect(browser.getTitle()).toEqual('About us - Oppia');
   });
 
   afterEach(function() {
     // Reset language back to English
-    browser.get('/splash');
+    browser.get('/about');
     _selectLanguage('English');
   });
 
   it('should change after selecting a different language', function() {
-    browser.get('/splash');
+    browser.get('/about');
     _selectLanguage('Español');
     browser.get('/library');
     expect(browser.getTitle()).toEqual('Biblioteca - Oppia');
@@ -74,7 +74,7 @@ describe('Site language', function() {
       function() {
     users.createUser('feanor@example.com', 'Feanor');
     users.login('feanor@example.com');
-    browser.get('/splash');
+    browser.get('/about');
     _selectLanguage('Español');
     browser.get('/library');
     expect(browser.getTitle()).toEqual('Biblioteca - Oppia');
@@ -102,7 +102,7 @@ describe('Site language', function() {
   it('should not change in an exploration', function() {
     users.createUser('mangue@example.com', 'Mangue');
     users.login('mangue@example.com', true);
-    browser.get('/splash');
+    browser.get('/about');
     _selectLanguage('Español');
     admin.reloadExploration('protractor_test_1.yaml');
     // Open exploration