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

The Python streaming example will break if you use longer keys or values #147

Closed
cartershanklin opened this issue Jul 30, 2019 · 3 comments

Comments

@cartershanklin
Copy link
Member

The Python streaming example at https://github.com/oracle/oci-python-sdk/blob/master/examples/stream_example.py uses the codecs library to perform base64 encoding.

This is fine until your key or value length gets around 64 or so. At that point the codecs approach will insert a linefeed to break lines into a certain max length.

[{
  "key": "QVNDLTIwMTktMDctMzBUMDc6Mzk6NDg=",
  "value": "QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJC\nQg=="
}]

This, in turn, causes a message of the form:

oci.exceptions.ServiceError: {'opc-request-id': '47F4B3A3FB6A4B5AA32B58DC38BCBC19/7AEE33713B629408FE514713ECF0594D/A21AC3A21C520739739D3A3AFE3BC1D4', 'code': 'InvalidParameter', 'message': 'Unable to parse JSON body', 'status': 400}

This may be considered a backend glitch in the streaming service, not sure.

Anyway it's straightforward to be more robust at the Python level by using the base64 library instead as in:

encoded_value = base64.b64encode(value.encode()).decode()

I can confirm that this does not produce linefeeds and allows larger values to be streamed in.

@arthall
Copy link
Contributor

arthall commented Jul 30, 2019

Thanks @cartershanklin. I'll update the example.

@arthall
Copy link
Contributor

arthall commented Jul 31, 2019

Thanks again @cartershanklin for reporting this. The streaming team updated the example and it will be included with the next release.

@arthall
Copy link
Contributor

arthall commented Aug 6, 2019

The latest version of the example has been updated. I'm closing this issue now. Thanks again @cartershanklin

@arthall arthall closed this as completed Aug 6, 2019
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

2 participants