jeffkowalski/geeknote

Cant' edit with geeknote

Opened this issue · 11 comments

I was trying to edit. Managed to get my developer token and login. The search feature works, the show feature works, but editing not so much

Connecting to Evernote...Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1423, in main
    Notes().edit(**ARGS)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1024, in edit
    result = self._editWithEditorInThread(inputData, note, raw=raw, rawmd=rawmd)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 838, in _editWithEditorInThread
    editor = Editor(editor_userprop, note.content, noteExt_userprop, raw)
  File "/usr/lib/python2.7/site-packages/geeknote/editor.py", line 283, in __init__
    "of string, '%s' given." % type(content))
Exception: Note content must be an instance of string, '<type 'unicode'>' given.

Can someone help me out here?

What version of geeknote are you using?
What commandline were you using that gave you the error?

Hey,
Sorry for the lack of info.
Version is 2.0.14
I was trying to enter
geeknote edit --note text
I also run the py.test and this is the output

========================================= test session starts ==========================================
platform linux -- Python 3.6.5, pytest-3.6.2, py-1.5.3, pluggy-0.6.0
rootdir: /home/tobias/down/geeknote, inifile:
collected 0 items / 9 errors


================================================ ERRORS ================================================
_______________________________ ERROR collecting tests/test_argparser.py _______________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_argparser.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_argparser.py:3: in <module>
    from geeknote.argparser import *
E   ModuleNotFoundError: No module named 'geeknote'
________________________________ ERROR collecting tests/test_editor.py _________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_editor.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_editor.py:3: in <module>
    from geeknote.editor import Editor
E   ModuleNotFoundError: No module named 'geeknote'
________________________________ ERROR collecting tests/test_gclient.py ________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_gclient.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_gclient.py:5: in <module>
    from geeknote.gclient import CustomClient
E   ModuleNotFoundError: No module named 'geeknote'
_______________________________ ERROR collecting tests/test_geeknote.py ________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_geeknote.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_geeknote.py:6: in <module>
    from cStringIO import StringIO
E   ModuleNotFoundError: No module named 'cStringIO'
________________________________ ERROR collecting tests/test_gnsync.py _________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_gnsync.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_gnsync.py:3: in <module>
    from geeknote.gnsync import remove_control_characters
E   ModuleNotFoundError: No module named 'geeknote'
__________________________________ ERROR collecting tests/test_out.py __________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_out.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_out.py:7: in <module>
    from cStringIO import StringIO
E   ModuleNotFoundError: No module named 'cStringIO'
________________________________ ERROR collecting tests/test_sandbox.py ________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_sandbox.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_sandbox.py:3: in <module>
    from geeknote import config
E   ModuleNotFoundError: No module named 'geeknote'
________________________________ ERROR collecting tests/test_storage.py ________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_storage.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_storage.py:4: in <module>
    from sqlalchemy.engine import create_engine
E   ModuleNotFoundError: No module named 'sqlalchemy'
_________________________________ ERROR collecting tests/test_tools.py _________________________________
ImportError while importing test module '/home/tobias/down/geeknote/tests/test_tools.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_tools.py:4: in <module>
    from geeknote.tools import checkIsInt, strip, decodeArgs,\
E   ModuleNotFoundError: No module named 'geeknote'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 9 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================= 9 error in 0.28 seconds ========================================
[tobias@tobias-pc geeknote]$ py.test
========================================= test session starts ==========================================
platform linux -- Python 3.6.5, pytest-3.6.2, py-1.5.3, pluggy-0.6.0
rootdir: /home/tobias/down/geeknote, inifile:
collected 0 items / 9 errors                        

Let me know if you might need something else from me.
Cheers

I cannot reproduce this error.

Would you test with python2?
I don't believe geeknote runs under python3 yet.

Under python2, I see this:

$ py.test                                                                                                                               

===================================================================================== test session starts =====================================================================================
platform linux2 -- Python 2.7.12, pytest-3.3.0, py-1.5.2, pluggy-0.6.0
rootdir: /home/jeff/Dropbox/workspace/geeknote, inifile:
collected 113 items                                                                                                                                                                           

tests/test_argparser.py ..............                                                                                                                                                  [ 12%]
tests/test_editor.py .......                                                                                                                                                            [ 18%]
tests/test_gclient.py ..                                                                                                                                                                [ 20%]
tests/test_geeknote.py ......                                                                                                                                                           [ 25%]
tests/test_gnsync.py ....                                                                                                                                                               [ 29%]
tests/test_out.py .................                                                                                                                                                     [ 44%]
tests/test_sandbox.py ssssssssssssssss                                                                                                                                                  [ 58%]
tests/test_storage.py ...................................                                                                                                                               [ 89%]
tests/test_tools.py ............                                                                                                                                                        [100%]

============================================================================ 97 passed, 16 skipped in 1.78 seconds ============================================================================ 

Hi,
I am also having the same problem and I am running with python2.

Geeknote version 2.0.14

When I run py.test in the git repository, I get

============================================================== test session starts ===============================================================
platform linux2 -- Python 2.7.15, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: .../git_projects/geeknote, inifile:
collected 113 items                                                                                                                              

tests/test_argparser.py ..............                                                                                                     [ 12%]
tests/test_editor.py .......                                                                                                               [ 18%]
tests/test_gclient.py ..                                                                                                                   [ 20%]
tests/test_geeknote.py ......                                                                                                              [ 25%]
tests/test_gnsync.py ....                                                                                                                  [ 29%]
tests/test_out.py .................                                                                                                        [ 44%]
tests/test_sandbox.py ssssssssssssssss                                                                                                     [ 58%]
tests/test_storage.py ...................................                                                                                  [ 89%]
tests/test_tools.py ............                                                                                                           [100%]

===================================================== 97 passed, 16 skipped in 1.29 seconds ======================================================

EDIT:
Some more stuff: I am running Arch and I have been having the same problem since quite some time.

python2 /usr/bin/geeknote edit food

>>  : Connecting to Evernote...Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1423, in main
    Notes().edit(**ARGS)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1024, in edit
    result = self._editWithEditorInThread(inputData, note, raw=raw, rawmd=rawmd)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 838, in _editWithEditorInThread
    editor = Editor(editor_userprop, note.content, noteExt_userprop, raw)
  File "/usr/lib/python2.7/site-packages/geeknote/editor.py", line 283, in __init__
    "of string, '%s' given." % type(content))
Exception: Note content must be an instance of string, '<type 'unicode'>' given.

This is helpful, @Mladia.
Can you create a minimal note that exhibits the error?
Post here the content of a small note that shows the problem.
That would help me track it down.

➜ geeknote create --title "example" --content "This is an example note"
Note successfully created.
➜ geeknote show "example"
################### URL ###################
NoteLink: https://...
WebClientURL: https://...
################## TITLE ##################
example
=================== META ==================
Notebook: general
Created: 2018-07-18
Updated: 2018-07-18
|||||||||||||||| REMINDERS ||||||||||||||||
Order: None
Time: None
Done: None
----------------- CONTENT -----------------
This is an example note
➜ geeknote edit "example"   
>   : Connecting to Evernote...Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1423, in main
    Notes().edit(**ARGS)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1024, in edit
    result = self._editWithEditorInThread(inputData, note, raw=raw, rawmd=rawmd)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 838, in _editWithEditorInThread
    editor = Editor(editor_userprop, note.content, noteExt_userprop, raw)
  File "/usr/lib/python2.7/site-packages/geeknote/editor.py", line 283, in __init__
    "of string, '%s' given." % type(content))
Exception: Note content must be an instance of string, '<type 'unicode'>' given.

And also

➜ python2 /usr/bin/geeknote edit "example"
>   : Connecting to Evernote...Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1423, in main
    Notes().edit(**ARGS)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1024, in edit
    result = self._editWithEditorInThread(inputData, note, raw=raw, rawmd=rawmd)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 838, in _editWithEditorInThread
    editor = Editor(editor_userprop, note.content, noteExt_userprop, raw)
  File "/usr/lib/python2.7/site-packages/geeknote/editor.py", line 283, in __init__
    "of string, '%s' given." % type(content))
Exception: Note content must be an instance of string, '<type 'unicode'>' given.

Also

➜ python2 --version
Python 2.7.15

This is strange, because everything works on my Fedora system, as it should be.

Thanks for providing the example, @Mladia. Regrettably, I cannot reproduce the error.
I tried your example, and even made one with that intentionally contains a unicode character, but cannot encounter the error in either case.

$ geeknote show UnicodeExample                                                                                               

################### URL ###################
NoteLink: https://www.evernote.com/shard/s1/nl/2079/db025412-bd04-4b19-9efd-8546908b18ea                                               
WebClientURL: https://www.evernote.com/Home.action?#n=db025412-bd04-4b19-9efd-8546908b18ea                                             
################## TITLE ##################
UnicodeExample
=================== META ==================
Notebook: EverNote
Created: 2018-07-18
Updated: 2018-07-18
|||||||||||||||| REMINDERS ||||||||||||||||
Order: None
Time: None
Done: None
----------------- CONTENT -----------------
UnicodeExample

This is an example note, with a "༃" unicode character

Hi, I don't know, if this would help. I printed the variable content before exception test

➜ geeknote show example1        
################### URL ###################
NoteLink: https://www.evernote.com/shard/s259/nl/33061411/66d2511b-4f4f-4cd9-912b-ed724bb0602d
WebClientURL: https://www.evernote.com/Home.action?#n=66d2511b-4f4f-4cd9-912b-ed724bb0602d
################## TITLE ##################
example1
=================== META ==================
Notebook: general
Created: 2018-07-20
Updated: 2018-07-20
|||||||||||||||| REMINDERS ||||||||||||||||
Order: None
Time: None
Done: None
----------------- CONTENT -----------------
This is an example note



~ took 2s 
➜ geeknote edit example1
    : Connecting to Evernote...content  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note><p>This is an example note</p>
</en-note>
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1423, in main
    Notes().edit(**ARGS)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 1024, in edit
    result = self._editWithEditorInThread(inputData, note, raw=raw, rawmd=rawmd)
  File "/usr/lib/python2.7/site-packages/geeknote/geeknote.py", line 838, in _editWithEditorInThread
    editor = Editor(editor_userprop, note.content, noteExt_userprop, raw)
  File "/usr/lib/python2.7/site-packages/geeknote/editor.py", line 286, in __init__
    "of string, '%s' given." % type(content))
Exception: Note content must be an instance of string, '<type 'unicode'>' given.

EDIT: I removed the verification if content is of type unicode and editing works for this particular note at least.

I patched it up a bit, it works now. I had to place a couple of note.content.docode/encode('utf-8') in geeknote.py here and there. Not pretty, but it does the job for now.

---../git_projects/geeknote/geeknote/geeknote.py      2018-07-18 12:44:28.360435870 +0200
+++ /usr/lib/python2.7/site-packages/geeknote/geeknote.py       2018-08-02 02:11:32.492854508 +0200
@@ -368,7 +368,7 @@
 
         if content:
             try:
-                note.content = content.encode('utf-8')
+                note.content = content.decode('utf-8')
             except UnicodeDecodeError:
                 note.content = content
 
@@ -835,6 +835,7 @@
                 self.getEvernote().loadLinkedNoteContent(note)
             else:
                 self.getEvernote().loadNoteContent(note)
+            note.content = note.content.encode('utf-8')
             editor = Editor(editor_userprop, note.content, noteExt_userprop, raw)
         else:
             editor = Editor(editor_userprop, '', noteExt_userprop, raw)
@@ -1060,6 +1061,7 @@
 
         out.preloader.setMessage("Loading note...")
         self.getEvernote().loadNoteContent(note)
+        note.content = note.content.encode('utf-8')
 
         if raw:
             out.showNoteRaw(note)

Those are the changes, that I've made. Note, that I have not tested everything in geeknote, to see if it works and I don't normally programm in python, so make this changes only if you have the same problems.

Hey Guys, thanks for handling this issue, saved an Evernotelife. Ran into the same issue recently, added @Mladia code and the download worked smoothly again, but i had trouble uploading a modified note afterwards.
The problem was caused by german umlauts( ä ö ü ), here the addition:

        logging.debug("Update note : %s", note)

        if not shared:
            note.content = note.content.decode('utf-8') # <-- Row 443 - Added decoding before updating
            self.getNoteStore().updateNote(self.authToken, note)
        else:
            self.sharedNoteStore.updateNote(self.sharedAuthToken, note)
        return True