Giter Site home page Giter Site logo

Comments (14)

urschrei avatar urschrei commented on June 2, 2024 2

Well this is a little embarrassing. Thanks for the detective work @MingweiSamuel. I've got some more changes to incorporate, and I'll cut a 1.3.8 release this weekend. @paregorios, sorry about the interminable wait…

from pyzotero.

paregorios avatar paregorios commented on June 2, 2024

FWIW, it looks to me like the code needs to be modified from hard-coding in the "/users/" string to some logic that figures out what kind of a library we're working with.

from pyzotero.

paregorios avatar paregorios commented on June 2, 2024

It looks to me like addressing this might be as simple as making use of the library_type attribute that's already defined on the Zotero class. I think this could be done by altering lines 670-674 in zotero.py to read as follows:

if not parentid:
    liblevel = '/{t}/{u}/items?key={k}'
else:
    liblevel = '/{t}/{u}/items/{i}/children?key={k}'

and then altering lines 681-688 as follows:

req = requests.post(
    url=self.endpoint
    + liblevel.format(
        t=self.library_type,
        u=self.library_id,
        i=parentid,
        k=self.api_key),
    data=to_send,
    headers=headers)

or am I missing something?

from pyzotero.

paregorios avatar paregorios commented on June 2, 2024

@atripavan if the suggestion in the previous comment looks credible to you, why not try forking this repos and then make and test the modification in that fork? If it can be made to work, then our project wouldn't be blocked and we could give back to the pyzotero owners for all the goodness we've got out of the package so far by issuing a pull request against this repos that they could pick up, evaluate, and incorporate as they see fit on their timeline.

from pyzotero.

atripavan avatar atripavan commented on June 2, 2024

I will try doing that Tom. Thanks!

from pyzotero.

urschrei avatar urschrei commented on June 2, 2024

I've just incorporated @paregorios's fix into dev. If you could test it and ensure it works (looks OK to me), I'll push an update to PyPI on Monday.

from pyzotero.

atripavan avatar atripavan commented on June 2, 2024

Thank you Stephan(@urschrei)!

I tried with the dev code, and am getting a different error:

Traceback (most recent call last):
  File "C:\Users\Pavan\workspace2\ZoteroTest\atri\zotero\test\zot_html_attachment.py", line 51, in <module>
    addHTMLAtchmnt('9U9NBFEF')
  File "C:\Users\Pavan\workspace2\ZoteroTest\atri\zotero\test\zot_html_attachment.py", line 25, in addHTMLAtchmnt
    zot.attachment_simple(['htmlattchmnt.html'], itemId)
  File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 1033, in attachment_simple
    return self._attachment(to_add, parentid)
  File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 784, in _attachment
    created = create_prelim(payload)
  File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 694, in create_prelim
    error_handler(req)
  File "C:\Python27\lib\site-packages\pyzotero\zotero.py", line 1240, in error_handler
    raise error_codes.get(req.status_code)(err_msg(req))
pyzotero.zotero_errors.UnsupportedParams: 
Code: 400
URL: https://api.zotero.org/groups/<groupID>/items/9U9NBFEF/children?key=<apiKey>
Method: POST
Response: Cannot change 'filename' directly in group library

from pyzotero.

urschrei avatar urschrei commented on June 2, 2024

Could you verify whether it works on a user, as opposed to group library?

from pyzotero.

atripavan avatar atripavan commented on June 2, 2024

Yes it works fine on user library

from pyzotero.

urschrei avatar urschrei commented on June 2, 2024

It looks like you're not allowed to edit the filename on child items in group libraries using the API:
https://www.zotero.org/support/dev/web_api/v3/file_upload

contentType, charset, filename, md5, and mtime can be edited directly in personal libraries for WebDAV-based file syncing. They cannot be edited directly in group libraries and should not be edited directly in personal libraries using Zotero File Storage, which provides an atomic method (detailed below) for setting the properties along with the corresponding file.

from pyzotero.

atripavan avatar atripavan commented on June 2, 2024

@urschrei
Just so you know, I am not trying to edit an existing child item, but trying to create a new file attachment as a child item. And am just passing the path to the file that needs to be attached and parent_item_id to the function(attachment_simple)
Not sure if this is something that needs to be addressed at the Zotero API level.

from pyzotero.

MingweiSamuel avatar MingweiSamuel commented on June 2, 2024

Maybe gravedigging, but ran into the original issue (?) described in this thread today on version 1.3.7

from pyzotero import zotero
zot = zotero.Zotero(..., 'group', ...)
zot.attachment_simple([ 'puppy.png' ])

Seems the problem is the hardcoded "users" in

pyzotero/pyzotero/zotero.py

Lines 1671 to 1674 in af73d6b

url=self.zinstance.endpoint
+ "/users/{u}/items/{i}/file".format(
u=self.zinstance.library_id, i=reg_key
),

Changing it to the following worked:

url=self.zinstance.endpoint
+ "/{t}/{u}/items/{i}/file".format(
    t=self.zinstance.library_type,
    u=self.zinstance.library_id, i=reg_key
),

from pyzotero.

MingweiSamuel avatar MingweiSamuel commented on June 2, 2024

It also seems that this needs to be updated? It only seemed to cause problems when I used attachment_both instead of attachment_simple, not sure

pyzotero/pyzotero/zotero.py

Lines 1619 to 1621 in 65da8ef

+ "/users/{u}/items/{i}/file".format(
u=self.zinstance.library_id, i=reg_key
),

from pyzotero.

urschrei avatar urschrei commented on June 2, 2024

πŸ€¦β€β™‚οΈ
Fixed and released as 1.3.9

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.