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

Meta issue for JSONDecode errors we see often lately #163

Open
JOJ0 opened this issue Nov 15, 2024 · 2 comments
Open

Meta issue for JSONDecode errors we see often lately #163

JOJ0 opened this issue Nov 15, 2024 · 2 comments

Comments

@JOJ0
Copy link
Contributor

JOJ0 commented Nov 15, 2024

Several users have reported similar randomly happening JSONDecode errors when retrieving arbitrary stuff via python3-discogs-client. I experienced it myself and post my experience soon. I'd like to summarize discussion and improvement suggestions in this issue here.

In my opinion it looks like api.discogs.com responds with unexpected data but only sometimes. I would guess it is a problem on their end for whatever reason, and they might be aware of and working on it already, or not..... In the end we have to live with it and find a workaround.

A second reason is that our backoff mechanism could be faulty or not compatible anymore since something might have changed at Discogs. It worked very well for us so far and it's in place since ...about 4 years already....#34

Related reports so far:

Did any of you solve the issue simply with try/except catchin jsondecode errors? If yes, share you experience, maybe a simple fix like that can be included in python3-discogs-client already.

Can this problem be reproduced when using api.discogs.com simply with Python requests module only?

@JOJ0 JOJ0 changed the title Meta issue for JSONDecode error we see often lately Meta issue for JSONDecode errors we see often lately Nov 15, 2024
@JOJ0
Copy link
Contributor Author

JOJ0 commented Nov 22, 2024

This is what I do to catch such errors in an application using discogs_client. For example this loops through my sales inventory and imports into an sqlite database. Instead of crashing I'd rather have missing entries. This also includes an error counter, since I currently want to learn how often these errors happen.

            for listing in self.collection.me.inventory:
                try:
                    self.collection.create_sales_entry({
                        "d_sales_release_id": listing.release.id,
                        "d_sales_listing_id": listing.id,
                        "d_sales_release_url": listing.release.url,
                    })
                except JSONDecodeError as e:
                    log.error("Catched a JSONDecodeError. Not retrying! %s", e)
                    decode_err += 1
                except Exception as e:
                    log.error("Catched an Exception. Not retrying! %s", e)
                    other_err += 1

        print(f"Discogs JSONDecode errors : {decode_err}.")
        print(f"Other errors : {other_err}.")

I'm not 100% sure since this error is hard to reproduce but I'm pretty sure this must catch JSONDecodeErrors, no matter where they happen!

@JOJ0
Copy link
Contributor Author

JOJ0 commented Nov 22, 2024

@AnssiAhola do you think we could include the catching of the JSONDecodeError (only! not other exceptions!) into the core of the client?

I'm not sure if simply wrapping the "main fetch wrapper":

return request(
method=method, url=url, data=data,
headers=headers, params=params,
timeout=(self.connect_timeout, self.read_timeout)
)

in a try except is the best idea or an approach like the backoff decorator is a better solution:

def backoff(f):
"""
Wraps the request method of the Fetcher class to provide
exponential backoff if rate limit is hit.
"""

or is all this a bad idea anyway? And of course we should add tests for it!

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

1 participant