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

Content Negotiation fails with TypeError for non-dois #83

Closed
goerz opened this issue Oct 2, 2019 · 4 comments
Closed

Content Negotiation fails with TypeError for non-dois #83

goerz opened this issue Oct 2, 2019 · 4 comments
Labels
Milestone

Comments

@goerz
Copy link

goerz commented Oct 2, 2019

Content negotiation throws a TypeError if it is called as e.g.

habanero.cn.content_negotiation(query_bibliographic=query, limit=1)

whith some string query. This is due to the definition of CNRequest:

def CNRequest(url, ids = None, format = None, style = None,
        locale = None, **kwargs):

    ...

    if(len(ids) == 1):
        ...

With the above call, ids is passed as None, and the query is in the kwargs. The line that takes the len of ids then fails.

@sckott
Copy link
Owner

sckott commented Oct 2, 2019

Thanks for the issue @goerz

Hmm. For kwargs with content_negotiation I only support kwargs passed to requests.get, e.g. timeout, proxies - curl modifiers.

Field queries, e.g., query_bibliographic are only supported on the Crossref API, and the Crossref API is only used in content_negotation method when format="citeproc-json"

What's the use case? So I can try to direct you to the appropriate method. I'm not sure what the use case is because field queries are meant to filter a search down further, and CN is meant for getting citations for identifiers (there's no search component in CN)

@goerz
Copy link
Author

goerz commented Oct 3, 2019

The use case is "get the most likely BibTeX for a free-form query".

I can easily get around this assuming the "most likely record" has a DOI, by first doing record = Crossref().works(query_bibliographic=query, limit=1)['message']['items'][0] (get the most likely record for a query), extracting the DOI as record['DOI'], and then using the DOI for the content-negotiation (habanero.cn.content_negotiation(ids=DOI)).

Nonetheless, there's a bug in the CNRequest function: the function will always crashes if called with ids=None. This is clearly incompatible ids=None as the default value in the function declaration. As currently implemented, instead of

def CNRequest(url, ids = None, format = None, style = None,
locale = None, **kwargs):
you'd have to define

def CNRequest(url, ids, format = None, style = None,
        locale = None, **kwargs):

and require that ids is either a string, an int, or a list.

Of course, this will push up the problem up to any place where CNRequest is currently called without specifying ids.

Note that

def content_negotiation(ids = None, format = "bibtex", style = 'apa',
locale = "en-US", url = None, **kwargs):
also has incompatible default values. You probably want to check in that function that ids=None and format="bibtex" are not used together (although ids=None may still be OK for other formats, like the citeproc-json).

@sckott sckott added the bug label Oct 3, 2019
@sckott sckott added this to the v0.7 milestone Oct 3, 2019
@sckott
Copy link
Owner

sckott commented Oct 3, 2019

Thanks. For that use case. works is the best fit here for that use case, using code as you showed.

Agree, there's definitely a bug, and thanks for the details on it. i'll fix

@sckott sckott closed this as completed in 679e99f Nov 8, 2019
@sckott
Copy link
Owner

sckott commented Nov 8, 2019

@goerz can you reinstall and try again [sudo] pip [or pip3] install git+git://github.com/sckott/habanero.git#egg=habanero - ids param is now required (no default) and must be a str or a list of str's

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

No branches or pull requests

2 participants