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

Fix new JSONDecodeError #292

Closed
patudom opened this issue Jul 31, 2023 · 1 comment · Fixed by cosmicds/cds-api#77
Closed

Fix new JSONDecodeError #292

patudom opened this issue Jul 31, 2023 · 1 comment · Fixed by cosmicds/cds-api#77
Assignees
Labels
1. critical Must be fixed or implemented ASAP

Comments

@patudom
Copy link
Contributor

patudom commented Jul 31, 2023

This is a new error for me (and @johnarban) for newly created students when the app is first run.

For example, the app runs for student_id=4153 who already had galaxy measurements.

The following errors are returned if I use create_new_student=True or student_id=4160 whom I just created to test this:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
File ~/opt/anaconda3/envs/newbase/lib/python3.8/site-packages/requests/models.py:971, in Response.json(self, **kwargs)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File ~/opt/anaconda3/envs/newbase/lib/python3.8/json/__init__.py:357, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    354 if (cls is None and object_hook is None and
    355         parse_int is None and parse_float is None and
    356         parse_constant is None and object_pairs_hook is None and not kw):
--> 357     return _default_decoder.decode(s)
    358 if cls is None:

File ~/opt/anaconda3/envs/newbase/lib/python3.8/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File ~/opt/anaconda3/envs/newbase/lib/python3.8/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
Cell In[1], line 8
      3 filterwarnings(action="ignore", category=UserWarning)
      5 from cosmicds.app import Application
----> 8 app = Application(story='hubbles_law', update_db=True, show_team_interface=False, allow_advancing=False, create_new_student=True)
      9 # app = Application(story='hubbles_law', update_db=True, show_team_interface=True, allow_advancing=True, student_id=4153) 
     11 app

File ~/Documents/GitHub/cosmicds/cosmicds/app.py:66, in Application.__init__(self, story, *args, **kwargs)
     64     self.observe(lambda x: self._setup(story, **kwargs), 'hub_user_info')
     65 else:
---> 66     self._setup(story, **kwargs)

File ~/Documents/GitHub/cosmicds/cosmicds/app.py:105, in Application._setup(self, story, **kwargs)
    101 # print(f"Student ID: {self.student_id}")
    102 # print(f"Class ID: {self.app_state.classroom['id']}")
    104 self._application_handler = JupyterApplication()
--> 105 self.story_state = story_registry.setup_story(story, self.session,
    106                                               self.app_state)
    108 self._get_student_options()
    110 # Initialize from database

File ~/Documents/GitHub/cosmicds/cosmicds/registries.py:71, in StoryRegistry.setup_story(self, name, session, app_state)
     68     state["stages"] = { int(k) : v for k, v in state["stages"].items() }
     69     story_state.update_from_dict(state)
---> 71 story_state.setup_for_student(app_state)
     73 for k, v in sorted(story_entry['stages'].items()):
     74     stage_cls = v['cls']

File ~/Documents/GitHub/hubbleds/src/hubbleds/story.py:687, in HubblesLaw.setup_for_student(self, app_state)
    685     app_state.update_db = False
    686 self.fetch_student_data()
--> 687 self.fetch_class_data()
    688 self.fetch_example_galaxy_data()

File ~/Documents/GitHub/hubbleds/src/hubbleds/story.py:627, in HubblesLaw.fetch_class_data(self)
    625     timestamp = floor(self.class_last_modified.timestamp() * 1000)
    626     class_data_url = f"{class_data_url}?last_checked={timestamp}"
--> 627 updated_meas, updated_data = self.fetch_measurement_data_and_update(class_data_url, CLASS_DATA_LABEL, prune_none=True, update_if_empty=False, check_update=check_update)
    629 if updated_data is not None:
    630     class_id = self.classroom["id"]

File ~/Documents/GitHub/hubbleds/src/hubbleds/story.py:524, in HubblesLaw.fetch_measurement_data_and_update(self, url, label, prune_none, make_writeable, check_update, update_if_empty, callbacks)
    523 def fetch_measurement_data_and_update(self, url, label, prune_none=False, make_writeable=False, check_update=None, update_if_empty=True, callbacks=None):
--> 524     measurements = self.fetch_measurements(url)
    525     need_update = check_update is None or check_update(measurements)
    526     if not need_update:

File ~/Documents/GitHub/hubbleds/src/hubbleds/story.py:520, in HubblesLaw.fetch_measurements(self, url)
    518 def fetch_measurements(self, url):
    519     response = requests.get(url)
--> 520     res_json = response.json()
    521     return res_json["measurements"]

File ~/opt/anaconda3/envs/newbase/lib/python3.8/site-packages/requests/models.py:975, in Response.json(self, **kwargs)
    971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Originally posted by @patudom in #287 (comment)

@patudom patudom added the 1. critical Must be fixed or implemented ASAP label Jul 31, 2023
@Carifio24 Carifio24 self-assigned this Jul 31, 2023
@Carifio24
Copy link
Member

@patudom Looks like this was a server-side issue which should be fixed with cosmicds/cds-api#77. Let me know if this pops up again.

@patudom patudom changed the title new JSONDecodeError Fix new JSONDecodeError Jul 31, 2023
@patudom patudom closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. critical Must be fixed or implemented ASAP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants