Giter Site home page Giter Site logo

Item creation failing about pyzotero HOT 15 CLOSED

urschrei avatar urschrei commented on June 16, 2024
Item creation failing

from pyzotero.

Comments (15)

urschrei avatar urschrei commented on June 16, 2024

Hmmm. Has item creation worked for you previously? (also, I removed the API key from your posted output)

from pyzotero.

avram avatar avram commented on June 16, 2024

It did when I first started testing out pyzotero, and collection deletion certainly worked. I'll experiment some more and try to pin this down.

And thanks for removing the key from the output here-- I remembered to catch it in the gist.

from pyzotero.

avram avatar avram commented on June 16, 2024

Basic creation works:


> > > server = zotero.Zotero('5770', '[key]')
> > > server
> > > <pyzotero.zotero.Zotero object at 0xb781680c>
> > > zitem = server.item_template("manuscript")
> > > zitem>>> zitem
> > > {u'numPages': '', u'itemType': u'manuscript', u'language': '', u'title': '', u'url': '', u'manuscriptType': '', u'rights': '', u'libraryCatalog': '', u'shortTitle': '', u'extra': '', u'accessDate': '', u'tags': [], u'place': '', u'notes': [], u'date': '', u'abstractNote': '', u'creators': [{u'lastName': '', u'creatorType': u'author', u'firstName': ''}], u'archiveLocation': '', u'archive': '', u'callNumber': ''}
> > > zitem["title"] = "ну?"
> > > zitem
> > > {u'numPages': '', u'itemType': u'manuscript', u'language': '', u'title': '\xd0\xbd\xd1\x83?', u'url': '', u'manuscriptType': '', u'rights': '', u'libraryCatalog': '', u'shortTitle': '', u'extra': '', u'accessDate': '', u'tags': [], u'place': '', u'notes': [], u'date': '', u'abstractNote': '', u'creators': [{u'lastName': '', u'creatorType': u'author', u'firstName': ''}], u'archiveLocation': '', u'archive': '', u'callNumber': ''}
> > > out = server.create_items([zitem])
> > > out
> > > [{u'itemType': u'manuscript', u'extra': u'', u'abstractNote': u'', u'archive': u'', u'title': u'\u043d\u0443?', u'archiveLocation': u'', u'etag': u'327ebd24f3a2d83bb8f820fdfc0cdacc', u'updated': 'Sat, 16 Jul 2011 11:29:34 MSK', u'tags': [], u'accessDate': u'', u'manuscriptType': u'', u'libraryCatalog': u'', u'callNumber': u'', u'key': u'QCWW78ZM', u'date': u'', u'numPages': u'', u'group_id': u'5770', u'shortTitle': u'', u'language': u'', u'rights': u'', u'url': u'', u'place': u'', u'creators': []}]
> > > 
> > > ```
> > > ```

from pyzotero.

urschrei avatar urschrei commented on June 16, 2024

It's an issue in the type field. When I removed yours ("\u0440\u0443\u043a\u043e\u043f\u0438\u0441\u044c"), I was able to create the item. So it seems the server is fussy about what it accepts in that field.

from pyzotero.

avram avatar avram commented on June 16, 2024

This is, as I expected, just a mistake on my part. The proper field for type on manuscripts is "manuscriptType" (ridiculous but true).

Would it be possible for pyzotero to do integrity checks, since it has the item template and can presumably can anticipate such errors (especially since Zotero's error seems to be pretty opaque)?

from pyzotero.

urschrei avatar urschrei commented on June 16, 2024

Hmmm. I'll have to think about how best to do it. I'm not currently storing the item-creation templates, but I suppose I can do that, check the user-created dicts, and raise an error if there are unknown fields in the item.

from pyzotero.

avram avatar avram commented on June 16, 2024

The integrity check could be made optional, if you think it will add unnecessary overhead. Maybe a new check_fields method?

The receiving API is pretty strict about things like this, and people will frequently trip up on field names, creator roles, and the like.

from pyzotero.

urschrei avatar urschrei commented on June 16, 2024

OK, I have this working. But I've now realised that there are fields missing from the data returned by a call to /itemFields (notes, tags, itemType, and creators), so an update will have to wait a little while, until I figure out whether they've been omitted on purpose.

from pyzotero.

avram avatar avram commented on June 16, 2024

I think that that's because the item types and creator types are returned by different calls: http://www.zotero.org/support/dev/server_api/write_api#get_valid_creator_types_for_an_item_type

from pyzotero.

urschrei avatar urschrei commented on June 16, 2024

Yes, but I'm not sure that behaviour is correct, since creators is a valid item field. I'll ask on zotero-dev shortly.

from pyzotero.

avram avatar avram commented on June 16, 2024

We could just consider those fields OK for all item types, since they are universal. I'm glad to work on this and test it myself, if you want to commit what you've written so far.

from pyzotero.

urschrei avatar urschrei commented on June 16, 2024

There's now a check_items() method: 1187a40

You can pass it a list of one or more dicts, and it'll compare them to the output of a call to item_fields(), raising a KeyError detailing the unknown keys if any are found.

from pyzotero.

avram avatar avram commented on June 16, 2024

Looks like you've added it to the docs as check_keys...

I'll try adding this to my script.

from pyzotero.

urschrei avatar urschrei commented on June 16, 2024

Fixed now. You'll have to pip install directly from the dev branch of the repo, btw. I'll merge it into master and upload it to pypi once I'm happy that it's behaving as it should.

from pyzotero.

avram avatar avram commented on June 16, 2024

This works for me! Closing the ticket, since it wasn't a bug in pyzotero to begin with, and now I have a way to avoid it.

from pyzotero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.