papis / papis-zotero

Zotero compatibility layer for papis
GNU General Public License v3.0
75 stars 17 forks source link

Trying to import from zotero but getting errors #8

Closed stasvlasov closed 1 year ago

stasvlasov commented 5 years ago

I installed papis-zotero==0.0.3 from pip. Exported zotero library to bibtex (lib.bib with valid links to files). Then I am tried the following:

papis-zotero import --from-bibtex lib/lib.bib --outfolder papis

And got lot of errors. I tried it both on Ubuntu and on MacOS. Strange but, errors seem different.

Any ideas how to get desired result?

Ubuntu 18.04:

INFO:papis:zotero:library 'papers'
Traceback (most recent call last):
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibdatabase.py", line 114, in expand_string
    self.strings[name])
KeyError: 'oct'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/papis-zotero", line 10, in <module>
    sys.exit(main())
  File "/home/stas/.local/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/stas/.local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/stas/.local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/stas/.local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/stas/.local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/papis_zotero/__init__.py", line 66, in do_importer
    from_bibtex, outfolder, link
  File "/usr/local/lib/python3.6/dist-packages/papis_zotero/importer.py", line 26, in import_from_bibtexfile
    entries = papis.bibtex.bibtex_to_dict(bib_file)
  File "/usr/local/lib/python3.6/dist-packages/papis/bibtex.py", line 166, in bibtex_to_dict
    entries = bibtexparser.loads(text).entries
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/__init__.py", line 48, in loads
    return parser.parse(bibtex_str)
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bparser.py", line 155, in parse
    self._expr.parseFile(bibtex_file_obj)
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibtexexpression.py", line 286, in parseFile
    return self.main_expression.parseFile(file_obj, parseAll=True)
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 2376, in parseFile
    return self.parseString(file_contents, parseAll)
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1818, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 4392, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 4332, in parseImpl
    loc, tmptokens = self_expr_parse( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3902, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3752, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3902, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3752, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3752, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 4392, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 4332, in parseImpl
    loc, tmptokens = self_expr_parse( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3752, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 4098, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3752, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1562, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 3902, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1595, in _parseNoCache
    tokens = fn( instring, tokensStart, retTokens )
  File "/home/stas/.local/lib/python3.6/site-packages/pyparsing.py", line 1217, in wrapper
    ret = func(*args[limit[0]:])
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibtexexpression.py", line 283, in _string_expr_parse_action
    return self._string_expr_parse_action_fun(s, l, t)
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bparser.py", line 196, in <lambda>
    BibDataStringExpression.expression_if_needed(t)))
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bparser.py", line 190, in <lambda>
    maybe_interpolate = lambda expr: as_text(expr)
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibdatabase.py", line 277, in as_text
    return text_string_or_expression.get_value()
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibdatabase.py", line 238, in get_value
    return ''.join([BibDataString.expand_string(s) for s in self.expr])
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibdatabase.py", line 238, in <listcomp>
    return ''.join([BibDataString.expand_string(s) for s in self.expr])
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibdatabase.py", line 204, in expand_string
    return string_or_bibdatastring.get_value()
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibdatabase.py", line 185, in get_value
    return self._bibdatabase.expand_string(self.name)
  File "/home/stas/.local/lib/python3.6/site-packages/bibtexparser/bibdatabase.py", line 116, in expand_string
    raise(UndefinedString(name))
bibtexparser.bibdatabase.UndefinedString: 'oct'

MacOS 10.13.6

INFO:papis:zotero:library 'papers'
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibdatabase.py", line 102, in expand_string
    self.strings[name])
KeyError: 'may'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/papis-zotero", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/papis_zotero/__init__.py", line 66, in do_importer
    from_bibtex, outfolder, link
  File "/usr/local/lib/python3.7/site-packages/papis_zotero/importer.py", line 26, in import_from_bibtexfile
    entries = papis.bibtex.bibtex_to_dict(bib_file)
  File "/usr/local/lib/python3.7/site-packages/papis/bibtex.py", line 166, in bibtex_to_dict
    entries = bibtexparser.loads(text).entries
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/__init__.py", line 48, in loads
    return parser.parse(bibtex_str)
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bparser.py", line 147, in parse
    self._expr.parseFile(bibtex_file_obj)
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibtexexpression.py", line 263, in parseFile
    return self.main_expression.parseFile(file_obj, parseAll=True)
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 2207, in parseFile
    return self.parseString(file_contents, parseAll)
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1666, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 4094, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 4033, in parseImpl
    loc, tmptokens = self_expr_parse( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3618, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3483, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3618, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3483, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3483, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 4094, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 4033, in parseImpl
    loc, tmptokens = self_expr_parse( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3483, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3805, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3483, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1412, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 3618, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1445, in _parseNoCache
    tokens = fn( instring, tokensStart, retTokens )
  File "/usr/local/lib/python3.7/site-packages/pyparsing.py", line 1082, in wrapper
    ret = func(*args[limit[0]:])
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibtexexpression.py", line 260, in _string_expr_parse_action
    return self._string_expr_parse_action_fun(s, l, t)
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bparser.py", line 184, in <lambda>
    BibDataStringExpression.expression_if_needed(t)))
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bparser.py", line 178, in <lambda>
    maybe_interpolate = lambda expr: as_text(expr)
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibdatabase.py", line 223, in as_text
    return text_string_or_expression.get_value()
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibdatabase.py", line 184, in get_value
    return ''.join([BibDataString.expand_string(s) for s in self.expr])
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibdatabase.py", line 184, in <listcomp>
    return ''.join([BibDataString.expand_string(s) for s in self.expr])
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibdatabase.py", line 150, in expand_string
    return string_or_bibdatastring.get_value()
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibdatabase.py", line 131, in get_value
    return self._bibdatabase.expand_string(self.name)
  File "/usr/local/lib/python3.7/site-packages/bibtexparser/bibdatabase.py", line 104, in expand_string
    raise(UndefinedString(name))
bibtexparser.bibdatabase.UndefinedString: 'may'
DancingQuanta commented 5 years ago

Looks like a bibtex parser choking on the badly written bibfile (which is probably separate from papis judging which python script was throwing the exception, bibtexparser in this case).

My suggestion is to inspect the bibfile you have made from your zotero library and find the bib items with the keywords oct and may (as seen in the traceback) and remove or fix them and try importing the resulting bibtex again. If errors persists with bibtexparser.bibdatabase.UndefinedString: with different terms you will have to repeatly remove or fix items whichwill be too much work. Then you may need to import selectively a group of items at a time and noting which group encounters an error.

Other option is to use a bibtex validator tool to check the bibfile (plenty of options online like bibchecker). Other way is using latex tools to create a pdf document with \nocite{*} and \bibliography{} in main document body to reveal any errors with bibtex file. See the method in this stackoverflow answer.

DancingQuanta commented 5 years ago

I started using papis today and do note the same issues with zotero import. Further investigations have shown that the error is due to the month field and is a flaw in bibtexparser not with papis or bibtex files. Please see the issue here.

DancingQuanta commented 5 years ago

It appears that the solution to this issue is probably fixed by this commit https://github.com/papis/papis/commit/eb9491a3495c1b34ff819cedf515b38d908cf957 which have not been released yet.

alejandrogallo commented 5 years ago

@DancingQuanta is right, this has been fixed in v0.9, unfortunately I haven't released it yet, it is coming soon though.

As a fix I would erase all lines of you bib file with month, since the month = oct expects a definition of the string oct, which is not present in your bibtex file, either this or you could also add definitions of oct on top of your bibfile, it should work then, in principle if you add

@string{ oct = "October" }

and accordingly for other months.

Sorry for the delay in the answer.

alexfikl commented 1 year ago

Hopefully this was actually fixed in papis 0.9. Feel free to reopen if it's still an issue!