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

Create new book fails: "Creation failed, book may already exist!" #186

Open
pawsen opened this issue Sep 22, 2020 · 10 comments · May be fixed by #411
Open

Create new book fails: "Creation failed, book may already exist!" #186

pawsen opened this issue Sep 22, 2020 · 10 comments · May be fixed by #411
Labels

Comments

@pawsen
Copy link

pawsen commented Sep 22, 2020

Creating a new book fails. As an example, take this guide book for rock climbing. The book exist on amazon,
https://www.amazon.it/Schweiz-Plaisir-sch%C3%B6nsten-Klettereien-Niveau-4a-6a/dp/3906087034

ol --create '{"identifiers": {"isbn_10": ["3906087034"]},
 "title": "Schweiz Plaisir",
 "publisher": "Filidor, Schweiz",
 "publish_date": "1993",
 "pages": "256",
 "author": "Jürg Von Känel"
}'

returns

Traceback (most recent call last):
  File "/usr/local/anaconda3/envs/bibliotek/bin/ol", line 8, in <module>
    sys.exit(main())
  File "/usr/local/anaconda3/envs/bibliotek/lib/python3.8/site-packages/olclient/cli.py", line 129, in main
    edition = ol.Work.create(book)
  File "/usr/local/anaconda3/envs/bibliotek/lib/python3.8/site-packages/olclient/openlibrary.py", line 235, in create
    ed = cls.OL.create_book(book, debug=debug)
  File "/usr/local/anaconda3/envs/bibliotek/lib/python3.8/site-packages/olclient/openlibrary.py", line 935, in create_book
    return self._create_book(
  File "/usr/local/anaconda3/envs/bibliotek/lib/python3.8/site-packages/olclient/openlibrary.py", line 983, in _create_book
    raise ValueError('Creation failed, book may already exist!')
ValueError: Creation failed, book may already exist!

Looking at https://openlibrary.org/api/books?bibkeys=ISBN:3906087034&jscmd=data&format=json, we see the book does not exist. Same for google books,
https://www.googleapis.com/books/v1/volumes?q=isbn:3906087034&fields=items/volumeInfo(title,subtitle,authors,publisher,publishedDate,language,industryIdentifiers,pageCount,imageLinks.thumbnail,categories)&maxResults=1

I am using the latest git version. But I get same response using the version from pip.

Am I doing something wrong?

@LeadSongDog
Copy link

That author’s record did not exist, though there were two records for them without the umlauts.

@pawsen
Copy link
Author

pawsen commented Sep 22, 2020

Ok, then maybe I don't understand the process of creating a new book using the client.
What should I do create the book? Can you point me towards some documentation or give an example?

@LeadSongDog
Copy link

I’m not sure if the client is able to create new authors yet. It doesn’t look like it to me. I raised an issue.

@pawsen
Copy link
Author

pawsen commented Sep 24, 2020

Ok. Another question(though not related to this issue),

How do I get the olid for an Edition, if I know the olid for a Work?

One example,

ol --get-work --title 'No latitude for error'
{"py/object": "olclient.common.Book", "authors": [{"name": "Sir Edmund Hillary", "olid": "OL78637A"}], "cover": "", "identifiers": {"goodreads": [], "isbns": [], "lccn": ["61003313", "61011015"], "librarything": ["4120408"], "oclc": ["487167"], "olid": ["OL888738W"]}, "pages": null, "publish_date": 1961, "publisher": "Hodder & Stoughton", "subtitle": null, "title": "No latitude for error"}

With Work olid=OL888738W how do I get the possible Editions(and ISBNs)?

Looking at https://openlibrary.org/works/OL888738W.json gives nothing, but from https://openlibrary.org/works/OL888738W I find there are two Editions.

@LeadSongDog
Copy link

LeadSongDog commented Sep 24, 2020

The doc at https://github.com/internetarchive/openlibrary-client#command-line-tool would seem to suggest trying:
ol —get-book —olid OL888738W

@pawsen
Copy link
Author

pawsen commented Sep 24, 2020

Yes, but the required olid is the Edition olid(eg. ending with M). Using the command you suggest result in a error.

This would work

ol --get-book --olid OL5824058M

But I do not know how to get one of the Edition olid's from the Work olid.

@LeadSongDog
Copy link

Perhaps the command line tool just does not yet support that part of the API. The python library suggests that it someday could:
https://github.com/internetarchive/openlibrary-client#works

@pawsen
Copy link
Author

pawsen commented Sep 24, 2020

Oh, @LeadSongDog,

I am sorry. You are totally right. I removed my previous comment, which was wrong. Thank you for replying.

work = OL.Work.get('OL888738W')
work.editions

or using the web,

https://openlibrary.org/works/OL888738W.json
https://openlibrary.org/works/OL888738W/editions.json

or directly from ISBN(different book)
http://openlibrary.org/isbn/9780143127048.json

@hornc hornc added the bug label Jan 26, 2023
@hornc
Copy link
Collaborator

hornc commented Jan 26, 2023

This is still an issue, and looks like it affects all command line create operations.

From adding some more debugging to the client I see that the exact error from OL is:

<class 'AttributeError'> at /books/add
'authors'
Python 	/home/openlibrary/.local/lib/python3.11/site-packages/web/utils.py in __getattr__, line 105
Web 	POST https://openlibrary.org/books/add

I think that possibly there have been some changes to the /books/add endpoint around authors resolving to their OLIDs that may have broken this.

The error isn't limited to the CLI interface, ol.create_book() has the same problem.

@hornc
Copy link
Collaborator

hornc commented Jan 26, 2023

https://github.com/internetarchive/openlibrary/blob/c69c9f4526f193c1e9e4d46c1591839a41860f12/openlibrary/plugins/upstream/addbook.py#L241-L243

where i is

i | <Storage {'debug': 'true', 'id_name': 'isbn_10', 'author_key': 'new', 'author_name': 'Jürg Von Känel', 'publisher': 'Filidor, Schweiz', 'id_value': '3906087034', 'title': 'Schweiz Plaisir', 'publish_date': '1993', '_save': '', 'web_book_url': '', '_test': 'false'}>

The current code is expecting an authors key.

Looks like this changed in this commit, and has been broken for a loooong time:

internetarchive/openlibrary@4e489c4

I'd be inclined to scrap the /books/add endpoint and use the more current api method https://github.com/internetarchive/openlibrary/wiki/Endpoints#data-import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants