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 listen_bucket_notification #657

Merged
merged 2 commits into from
Jun 7, 2018
Merged

fix listen_bucket_notification #657

merged 2 commits into from
Jun 7, 2018

Conversation

WaYdotNET
Copy link
Contributor

use json.decoder.JSONDecodeError instead of SyntaxError

ref #652

use json.decoder.JSONDecodeError instead of SyntaxError
harshavardhana
harshavardhana previously approved these changes May 31, 2018
minio/api.py Outdated
@@ -505,7 +505,7 @@ def listen_bucket_notification(self, bucket_name, prefix='', suffix='',
event = json.loads(line)
if event['Records'] is not None:
yield event
except SyntaxError:
except json.decoder.JSONDecodeError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WaYdotNET thanks for the PR.

We actually want to support both python 2 & 3. Python 2 doesn't know json.decoder.JSONDecodeError and parsing wrong json raises ValueError exception. Now, since json.decoder.JSONDecodeError is a subclass of ValueError, catching ValueError instead of json.decoder.JSONDecodeError will work for both python 2 & 3.

What do you think ?

Copy link
Contributor Author

@WaYdotNET WaYdotNET Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadmeste @harshavardhana
I preferred check if JSONDecodeError exist :

try:
    from json.decoder import JSONDecodeError
except ImportError:
    JSONDecodeError = ValueError
    except JSONDecodeError:

What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WaYdotNET I am good with your idea.

fix python2 compatibility
@nitisht nitisht self-requested a review June 7, 2018 07:33
@nitisht nitisht merged commit 746e90f into minio:master Jun 7, 2018
@WaYdotNET WaYdotNET deleted the patch-1 branch June 7, 2018 08:10
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

Successfully merging this pull request may close these issues.

4 participants