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

StringIO and 'neptune.send_artifact' #323

Closed
BenAsaf opened this issue Dec 1, 2020 · 1 comment
Closed

StringIO and 'neptune.send_artifact' #323

BenAsaf opened this issue Dec 1, 2020 · 1 comment

Comments

@BenAsaf
Copy link

BenAsaf commented Dec 1, 2020

Hello,

It's a pleasure working with Neptune, thanks.
I am trying to log a StringIO as an artifact. I wish to avoid saving a temporary file in-order to log it and then proceed to remove it.

Neptune version: 0.4.126
It was installed using Conda on Ubuntu 18.04.
Python version 3.7.8

Here is a minimal example to reproduce:

import neptune
from io import StringIO
summary_string_io = StringIO()
summary_string_io.write("something, something.")
neptune.init('a/b')
neptune.create_experiment(name='minimal_example')
neptune.send_artifact(summary_string_io, destination="summary.txt")

The error I'm getting is (I omitted some of my paths):

Traceback (most recent call last):
File "", line 12, in
neptune.send_artifact(summary_string_io, destination="summary.txt")
File "lib/python3.7/site-packages/neptune/init.py", line 355, in send_artifact
return get_experiment().log_artifact(artifact, destination)
File "lib/python3.7/site-packages/neptune/experiments.py", line 620, in log_artifact
experiment=self)
File "lib/python3.7/site-packages/neptune/internal/storage/storage_utils.py", line 230, in upload_to_storage
upload_api_fun(**dict(kwargs, data=file_chunk_stream, progress_indicator=progress_indicator))
File "lib/python3.7/site-packages/neptune/internal/backends/hosted_neptune_backend.py", line 692, in upload_experiment_output
query_params={})
File "lib/python3.7/site-packages/neptune/internal/backends/hosted_neptune_backend.py", line 847, in _upload_loop
ret = with_api_exceptions_handler(self._upload_loop_chunk)(fun, part, data, **kwargs)
File "lib/python3.7/site-packages/neptune/utils.py", line 211, in wrapper
return func(*args, **kwargs)
File "lib/python3.7/site-packages/neptune/internal/backends/hosted_neptune_backend.py", line 865, in _upload_loop_chunk
response = fun(data=part.get_data(), headers=headers, **kwargs)
File "lib/python3.7/site-packages/neptune/internal/storage/datastream.py", line 34, in get_data
return io.BytesIO(self.data)
TypeError: a bytes-like object is required, not 'str'

I tried looking for examples but I couldn't find any.

Thank you,
Ben.

@szymon-kuklewicz
Copy link
Contributor

Hi Ben

Thank you for your kind words about Neptune.

I've been checking your issue and found out that despite the fact that you provided some content to the StringIO, Neptune could read only empty content. Traceback is related to the issue of wrong handling empty StringIO and we've just publish a fix release 0.4.127. It should be available to download very soon.

More interesting for you will be fixing the stream, so Neptune will be able to read it's content. In this fix I also updated the docs for log_artifact method(). According to the docs, when you write to some stream like StringIO, it's position is set to the end of the steam. When you now call read() on this stream, you won't get any content. You need to rewind the stream to the beginning (by calling seek(0) for example), so anyone (and Neptune) can read it.

Hope it will resolve your issue. Good luck with Neptune.

Kind regards,
Szymon

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