最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Python操作Evernote报错:raise evernote.edam.error.ttypes.EDAMSystemException

Python crifan 358浏览 0评论
折腾:
【未解决】自己写Python脚本同步印象笔记到WordPress
期间,用Evernote的自带的测试文件去测试,结果报错:
➜  EvernoteToWordpress cd /Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/crifan/.local/share/virtualenvs/EvernoteToWordpress-PC3x4gk8/bin/python /Users/crifan/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 64124 /Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress/libs/evernote-sdk-python3/sample/client/EDAMTest.py 
Is my Evernote API version up to date?  True


Traceback (most recent call last):
  File "/Users/crifan/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "/Users/crifan/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/Users/crifan/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/crifan/dev/dev_root/python/EvernoteToWordpress/EvernoteToWordpress/libs/evernote-sdk-python3/sample/client/EDAMTest.py", line 70, in <module>
    note_store = client.get_note_store()
  File "libs/evernote-sdk-python3/lib/evernote/api/client.py", line 106, in get_note_store
    note_store_uri = user_store.getNoteStoreUrl()
  File "libs/evernote-sdk-python3/lib/evernote/api/client.py", line 167, in delegate_method
    )(**dict(list(zip(arg_names, args))))
  File "libs/evernote-sdk-python3/lib/evernote/edam/userstore/UserStore.py", line 1156, in getNoteStoreUrl
    return self.recv_getNoteStoreUrl()
  File "libs/evernote-sdk-python3/lib/evernote/edam/userstore/UserStore.py", line 1181, in recv_getNoteStoreUrl
    raise result.systemException
evernote.edam.error.ttypes.EDAMSystemException: EDAMSystemException(message='authenticationToken', errorCode=8, rateLimitDuration=None)
去深入调试发现:
此处
libs/evernote-sdk-python3/lib/evernote/api/client.py
    def get_user_store(self):
        user_store_uri = self._get_endpoint("/edam/user")
...

    def get_note_store(self):
        user_store = self.get_user_store()
user_store_uri是
很明显应该是yinxiang.com,而不是evernote.com
class EvernoteClient(object):
    def __init__(self, **options):
        self.consumer_key = options.get('consumer_key')
        self.consumer_secret = options.get('consumer_secret')
        self.sandbox = options.get('sandbox', True)
        self.china = options.get('china', False)
        if self.sandbox:
            default_service_host = '
sandbox.evernote.com
'
        elif self.china:
            default_service_host = '
app.yinxiang.com
'
        else:
            default_service_host = '
www.evernote.com
'
        self.service_host = options.get('service_host', default_service_host)
        self.additional_headers = options.get('additional_headers', {})
        self.token = options.get('token')
        self.secret = options.get('secret')
此处判断逻辑好像有问题。
去看了看代码:
发现是可以修改代码逻辑,也可以去给EvernoteClient传入service_host
去试试:
# client = EvernoteClient(token=auth_token, sandbox=sandbox,china=china)
client = EvernoteClient(
    token=auth_token,
    sandbox=sandbox,
    china=china,
    service_host="
sandbox.yinxiang.com
"
)
结果就正常了:
【总结】
此处是:
国内版 印象笔记
沙箱模式
所以设置了:
sandbox=True
# china=False
china=True
也设置好了 sandbox.yinxiang.com的token
然后去运行代码,报错
调试发现是:
libs/evernote-sdk-python3/lib/evernote/api/client.py
class EvernoteClient(object):
    def __init__(self, **options):
    
    
...

            default_service_host = 'sandbox.evernote.com'
        elif self.china:
            default_service_host = 'app.yinxiang.com'
        else:
            default_service_host = 'www.evernote.com'
        self.service_host = options.get('service_host', default_service_host)
解决办法:
修改判断逻辑
或 传入对应参数:
libs/evernote-sdk-python3/sample/client/EDAMTest.py
sandbox=True
# china=False
china=True

# client = EvernoteClient(token=auth_token, sandbox=sandbox,china=china)
client = EvernoteClient(
    token=auth_token,
    sandbox=sandbox,
    china=china,
    service_host="sandbox.yinxiang.com"
)
都可以。

转载请注明:在路上 » 【已解决】Python操作Evernote报错:raise evernote.edam.error.ttypes.EDAMSystemException

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.186 seconds, using 23.37MB memory