-
Notifications
You must be signed in to change notification settings - Fork 318
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
Conversation
use json.decoder.JSONDecodeError instead of SyntaxError
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: |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
use json.decoder.JSONDecodeError instead of SyntaxError
ref #652