question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent exceptions when adding empty byte strings

See original GitHub issue

I am encountering an issue when adding strings of 0 length using add_bytes(bytes('')) (in https://github.com/oduwsdl/ipwb/issues/485).

Replication:

> import ipfsapi
> IPFS_API = ipfsapi.Client('localhost', 5001)
> IPFS_API.add_bytes('lorem')
u'QmeHxdVgh5BVLL7S7AvjrXqum8977XcPcfyHYUkoCG624N'
> IPFS_API.add_bytes('')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/utils.py", line 150, in wrapper
    res = cmd(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/client.py", line 2087, in add_bytes
    data=body, headers=headers, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 37, in wrapper
    return func(self, *args, **merged)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 170, in request
    files, headers, data)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 100, in _request
    files=files, headers=headers, data=data)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 77, in _do_request
    six.raise_from(exceptions.ConnectionError(error), error)
  File "/Users/machawk1/Library/Python/2.7/lib/python/site-packages/six.py", line 737, in raise_from
    raise value
ipfsapi.exceptions.ConnectionError: ConnectionError: [Errno 32] Broken pipe
> IPFS_API.add_bytes(bytes(''))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/utils.py", line 150, in wrapper
    res = cmd(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/client.py", line 2087, in add_bytes
    data=body, headers=headers, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 37, in wrapper
    return func(self, *args, **merged)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 170, in request
    files, headers, data)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 100, in _request
    files=files, headers=headers, data=data)
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/http.py", line 77, in _do_request
    six.raise_from(exceptions.ConnectionError(error), error)
  File "/Users/machawk1/Library/Python/2.7/lib/python/site-packages/six.py", line 737, in raise_from
    raise value
ipfsapi.exceptions.ConnectionError: ConnectionError: [Errno 32] Broken pipe
>>> 

…but sometimes from this same line with the same empty string I get:

> IPFS_API.add_bytes(bytes(''))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/ipfsapi/utils.py", line 151, in wrapper
    return res[self.field]
TypeError: list indices must be integers, not str

Is it in violation to add an empty string “as bytes” to IPFS using add_bytes()? Any clue why I would be getting multiple errors from the same line (replicable in interactive Python, too)?

ipfsapi 0.4.3 (originally experienced in 0.4.2a)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ntninjacommented, Oct 7, 2018

Turns out it’s actually a bug with go-IPFS: https://github.com/ipfs/go-ipfs/issues/5168 I’ll be pushing a mitigation soon.

1reaction
ibnesayeedcommented, Feb 15, 2019

I can confirm that it is working fine with go-IPFS v0.4.18. This ticket can perhaps be closed now.

$ ipfs --version
ipfs version 0.4.18
$ python
Python 2.7.15 (default, Oct 16 2018, 07:58:03) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipfsapi
>>> api = ipfsapi.connect('127.0.0.1', 5001)
>>> api.add_bytes(b'')
u'QmaRwA91m9Rdfaq9u3FH1fdMVxw1wFPjKL38czkWMxh3KB'
>>> api.cat('QmaRwA91m9Rdfaq9u3FH1fdMVxw1wFPjKL38czkWMxh3KB')
[]
>>> exit()
$ 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent treatment of empty strings vs. empty bytes · Issue #1218 ...
An application I am making needs to be able to receive bytes fields that are set to the empty buffer. I have generally...
Read more >
Should I Throw ArgumentNullException if a string is blank?
My question is, is it okay to throw an ArgumentNullException even if the string is equal to string.Empty? Because technically it isn't null....
Read more >
Inserting Byte[] data into SqlDataSource - Second Posting
I am trying to insert an image into database using SqlDataSource but I am getting an error saying can not convert Byte[] to...
Read more >
Resolve "GENERIC_INTERNAL_ERROR" when querying ...
GENERIC_INTERNAL_ERROR: Value exceeds MAX_BYTE: You might see this exception when the source data column has a numeric value exceeding the ...
Read more >
Backward Incompatible Changes - Manual - PHP
Unexpected characters in source files (such as NUL bytes outside of strings) will now result in a ParseError exception instead of a compile...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found