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

'_io.BytesIO' object has no attribute 'name' #175

Closed
jeffgerhard opened this issue Jan 4, 2017 · 3 comments
Closed

'_io.BytesIO' object has no attribute 'name' #175

jeffgerhard opened this issue Jan 4, 2017 · 3 comments

Comments

@jeffgerhard
Copy link

Hi,

I'm getting errors trying to upload a binary file-like object. This was working before I updated internetarchive a few weeks ago. (Usage: I'm compiling binary MARC records in python to upload alongside of existing PDF files.)

It seems like this update #162, when resolving this filename issue #163 in item.py, may not be taking into account file-like objects that don't have a name attribute? The relevant section is here.

I'm very much an amateur here so I could be overlooking something. I'm using Windows 7, Python 3.5.2. Here are my traceback messages, and I can supply my local code if it would help.

Traceback (most recent call last):
File "C:\Users\gerhardj\repos\sierra_api\new_pdf_upload.py", line 106, in metadata=md, verbose=True)
File "C:\Anaconda3\lib\site-packages\internetarchive\api.py", line 285, in upload request_kwargs=request_kwargs)
File "C:\Anaconda3\lib\site-packages\internetarchive\item.py", line 751, in upload request_kwargs=request_kwargs)
File "C:\Anaconda3\lib\site-packages\internetarchive\item.py", line 522, in upload_file
filename = body.name
AttributeError: '_io.BytesIO' object has no attribute 'name'

Thanks for any help or suggestions!

@jjjake
Copy link
Owner

jjjake commented Jan 5, 2017

Thanks for reporting this issue @jeffgerhard!

This could be addressed by not requiring a file-like object to have a name attribute if a key is specified. Then you could do something like:

>>> item.upload({'my_filename.txt': file_like_object})

In the meantime, I think you should be able to do something like the following to get around this issue:

>>> io_bytesio_obj.name = 'my_filename.txt'
>>> item.upload(ia_bytesio_obj)

Does that make sense? I'll try get around to resolving this issue soon.

@jeffgerhard
Copy link
Author

Hi Jake, that totally makes sense, I should have thought of that. The ideal scenario you mentioned first (basically as described in readthedocs) is what I was already doing before the name attr became required.

Thanks!

@jjjake
Copy link
Owner

jjjake commented Jan 6, 2017

Alright, I think d98925b should fix this. I haven't published a new version yet, but if you're able to install the github master branch this should now be fixed there.

This will be in version 1.2.0. I have a few other features I'm working on that I'd like to complete before I release this version.

Thanks again @jeffgerhard!

@jjjake jjjake closed this as completed Jan 6, 2017
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