urschrei / pyzotero

Pyzotero: a Python client for the Zotero API
https://pyzotero.readthedocs.org
Other
910 stars 100 forks source link

Zotero(None, None, api_key) gets rejected #119

Closed michi-zuri closed 4 years ago

michi-zuri commented 4 years ago

I have this function in my python script:

def _get_user_id(api_key):
    z = Zotero('AnyLibrary', 'AnyType', api_key)
    key_info = z.key_info()
    return key_info['userID']

I would like to simplify this to:

def _get_user_id(api_key):
    z = Zotero(api_key=api_key)
    key_info = z.key_info()
    return key_info['userID']

or

def _get_user_id(api_key):
    z = Zotero(None, None, api_key)
    key_info = z.key_info()
    return key_info['userID']

Problem description

At the moment, without stating arbitrary library ids and types, an error is raised: pyzotero.zotero_errors.MissingCredentials: Please provide both the library ID and the library type This is inappropriate [edit: not what I expected], since I am inspecting the api key to figure out which library IDs I have access to. The library type is discovered in this process as well.

Solution

A pull request is proposed with #118 to fix this behaviour.

urschrei commented 4 years ago

Michael, Please try to avoid blaming the Pyzotero API (and, by extension, its authors) for the fact that it doesn't do what you want it to do. I've commented on your PR separately.

michi-zuri commented 4 years ago

Dear Stephan, Please excuse my language, I didn't mean to insult anyone, but I can see what you mean and I am sorry for venting my frustration that is part of learning Python in that comment. I will think about what you wrote in the PR and try to come up with a method that doesn't rely on the Zotero instance for fetching key info. As it stands it is not more than an aesthetics issue, with the examples I had given doing what I need, so I'll close this issue for now. And last but not least, a big thanks to you and all collaborators for all their work!

urschrei commented 4 years ago

That's OK, no need to apologise! As I said, adding a key-only method is no problem.