Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Fix JSONDecoder 'encoding' bug #649

Merged
merged 5 commits into from
Jun 5, 2023
Merged

Fix JSONDecoder 'encoding' bug #649

merged 5 commits into from
Jun 5, 2023

Conversation

kt474
Copy link
Member

@kt474 kt474 commented May 31, 2023

Summary

This has been reported 3 times now - #528, #647, and on slack. I have been unable to replicate this issue but this was a suggested fix.

JSONDecoder.__init__() got an unexpected keyword argument 'encoding'

The keyword argument encoding was removed in python 3.9 https://docs.python.org/3/library/json.html#json.loads but I'm not sure if that's related to this error (2 of the users were using python 3.10, 1 was using python 3.8).

thoughts @jyu00 @merav-aharoni?

Update: figured it out, explained in comment below

Details and comments

@merav-aharoni
Copy link
Collaborator

I don't really have anything helpful to say. I ran the two cases using python 3.10 and did not get the error.
Perhaps add a print a better error message or warning, in case encoding appears, to print the full response from self.session.get(self.get_url("self")).json()) to help debug next time this happens.

@kt474
Copy link
Member Author

kt474 commented Jun 1, 2023

After lots of digging, I found that we are having the same issue reported in psf/requests#4842.

It appears that when simplejson is in the environment requests preferentially imports it. However, the arguments accepted by JSONDecoder are inconsistent between the standard library json and simplejson leading to errors when using the standard json.JSONDecoder when simplejson is in the environment.

Since simplejson is not part of this repo the easy solution would be to inform the users to uninstall this package but since this issue has come up a lot recently, we could add some warning/check.

@kt474 kt474 marked this pull request as ready for review June 1, 2023 17:13
@coveralls
Copy link

Pull Request Test Coverage Report for Build 5147280181

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.008%) to 51.854%

Totals Coverage Status
Change from base Build 5147270039: 0.008%
Covered Lines: 3133
Relevant Lines: 6042

💛 - Coveralls

@kt474 kt474 merged commit 5583504 into Qiskit:main Jun 5, 2023
@kt474 kt474 deleted the json-decoder-bug branch June 5, 2023 17:44
@kt474 kt474 restored the json-decoder-bug branch June 5, 2023 17:46
@kt474 kt474 deleted the json-decoder-bug branch June 5, 2023 17:46
@kt474 kt474 added the Changelog: Bugfix Include in the Fixed section of the changelog label Jun 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Changelog: Bugfix Include in the Fixed section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants