Menotexport icon indicating copy to clipboard operation
Menotexport copied to clipboard

UnboundLocalError: local variable 'tags' referenced before assignment

Open ludzeller opened this issue 6 years ago • 4 comments

Hi!

I ran

python menotexport.py -ns -f "Promotion" /Users/ludwig/Library/Application\ Support/Mendeley\ Desktop/[email protected]@www.mendeley.com.sqlite output

and I get

=============================== 27/167 ===============================
# <Menotexport>: Processing folder: "Promotion/Projekte /
Kolloquien/Kritische Artefakte/Bibliografie"
Traceback (most recent call last):
  File "menotexport.py", line 1455, in <module>
    args.separate,args.zotero,args.verbose)
  File "menotexport.py", line 1302, in main
    fidii,fnameii,allfolders,action,separate,iszotero,verbose)
  File "menotexport.py", line 1017, in processFolder
    annotations = getDocNotes(db, annotations, folderid,foldername)
  File "menotexport.py", line 645, in getDocNotes
    meta['tags']=tags
UnboundLocalError: local variable 'tags' referenced before assignment

Any ideas?

As you can see 26 folders (I guess?) were processed successfully...

ludzeller avatar Oct 05 '17 17:10 ludzeller

Hi ludzeller,

Yes it got 26 folders (subfolders in Promotion to be specific) done but failed at the 27th. I had some trouble reproducing your error, but it is certainly some error in the code. Can you give me the version of Mendeley you are using, and some other info regarding the document that failed at? Apparently it failed at retrieving the "tags" field, so what's in the "tags" field in the document it failed in your Mendeley? And lastly, you are using in windows right?

Sorry for the trouble.

Xunius avatar Oct 06 '17 05:10 Xunius

Thanks for getting back so fast and no need to apologise, I am looking forward to being able to make plain text from my notes... :)

I am on macOS 10.12.4 (16E195) using Mendeley 1.17.11.

I realised that I had plenty of / characters in my folder names, but also after removing them, I got the same error.

The folder it hangs has three entries, one with one PDF, one with three PDFs and one with none.

I don't know which one was processed first. But one of the PDF has the tag "Civilization; Europe; Fetishism; Folder - Ergänzung SNF 1" and another one "Folder - Ergänzung SNF 1".

Actually I never add tags. These have been added by Mendeley or some other tools somehow. I wouldn't mind if there was a flag to simply omit the tags?

For a test I just removed these two tags and it was able to process the folder then... Could it be some bad characters?

ludzeller avatar Oct 06 '17 11:10 ludzeller

Many thanks for the feedback. However I still couldn't reproduce the error, it doesn't seem to be bad characters though. How is you export working? I've made a dirty patch that should get it working but will lose the tags when that error would occur. If you don't mind losing those tags, you could either delete them manually in Mendeley, or download the code again and give it a try. P.S. I never realized that you can attach multiple files to a single document. I have no idea how that would affect this software, I'll mess around a bit more. What's your user case when having 3 files attached to a doc?

Xunius avatar Oct 06 '17 14:10 Xunius

Sorry for getting back so late. After I removed the probably filthy tags (just in one entry), I was able to process my whole library! But I guess the new flag could be handy at some point, at least for others!

And yes, I have some entries with multiple PDFs attached. In one case, where I had two PDF files, your script just created a file for the second PDF - Mendeley added a (2) to the filename of the PDF and your output mirrors that. The first PDF did not have any notes, so I cannot say if your code would always take the last (or second) PDF of that array - or if it only skips files without any annotations added. The latter was the case for that PDF #1.

Should I do more testing? Multiple files are rare for me, but they do occur. And of course it would be good to have all of them processed.

ludzeller avatar Oct 17 '17 15:10 ludzeller