Evernote Python API "Invalid header value" 在 Mac 上使用 Jupyter iPython 时收到身份验证错误
Evernote Python API "Invalid header value" authentication error received when using Jupyter iPython on Mac
我在使用笔记本或命令行中的 Evernote Python API 和 Jupyter iPython 时遇到了一些困难。奇怪的是,以前还能这样,现在好像坏掉了。奇怪的是,这只是我 Mac 书中的新行为。这在我的电脑上的 Jupyter iPython 中仍然有效。我怀疑我的设置有问题,但我不确定如何进一步诊断它。
首先,我能够连接到 Mac 运行 上的 API 以下 .py 文件:
from evernote.api.client import EvernoteClient
dev_token = "my_dev_token_here"
client = EvernoteClient(token=dev_token)
noteStore = client.get_note_store()
nbs= noteStore.listNotebooks()
for nb in nbs: print nb.name
我得到了预期的输出——我的 Evernote 笔记本列表。
接下来,我尝试在 ipython CLI 实例中发出这些命令。我收到以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-3796a38811af> in <module>()
----> 1 ns = client.get_note_store()
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/api/client.pyc in get_note_store(self)
66 def get_note_store(self):
67 user_store = self.get_user_store()
---> 68 note_store_uri = user_store.getNoteStoreUrl()
69 store = Store(self.token, NoteStore.Client, note_store_uri)
70 if not store: # Trick for PyDev code completion
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/api/client.pyc in delegate_method(*args, **kwargs)
136 return functools.partial(
137 targetMethod, authenticationToken=self.token
--> 138 )(**dict(zip(arg_names, args)))
139 else:
140 return targetMethod(*args, **kwargs)
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/edam/userstore/UserStore.pyc in getNoteStoreUrl(self, authenticationToken)
910 - authenticationToken
911 """
--> 912 self.send_getNoteStoreUrl(authenticationToken)
913 return self.recv_getNoteStoreUrl()
914
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/edam/userstore/UserStore.pyc in send_getNoteStoreUrl(self, authenticationToken)
919 args.write(self._oprot)
920 self._oprot.writeMessageEnd()
--> 921 self._oprot.trans.flush()
922
923 def recv_getNoteStoreUrl(self, ):
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/thrift/transport/THttpClient.pyc in _f(*args, **kwargs)
123 orig_timeout = socket.getdefaulttimeout()
124 socket.setdefaulttimeout(args[0].__timeout)
--> 125 result = f(*args, **kwargs)
126 socket.setdefaulttimeout(orig_timeout)
127 return result
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/thrift/transport/THttpClient.pyc in flush(self)
148 self.__http.putheader('Content-Length', str(len(data)))
149 for key, value in self.__headers.iteritems():
--> 150 self.__http.putheader(key, value)
151 self.__http.endheaders()
152
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.pyc in putheader(self, header, *values)
1033 for one_value in values:
1034 if _is_illegal_header_value(one_value):
-> 1035 raise ValueError('Invalid header value %r' % (one_value,))
1036
1037 hdr = '%s: %s' % (header, '\r\n\t'.join(values))
ValueError: Invalid header value 'en-devtoken:V=2 / 1.23; Python / 2.7.11 (default, Jan 22 2016, 08:29:18) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)];'
当 运行 Jupyter iPython 笔记本中的代码时,我得到了类似的结果。感谢您提供任何线索。
必须在最新的 SDK 1.25.2 上修复 Invalid header value
错误。请升级SDK后重试
我在使用笔记本或命令行中的 Evernote Python API 和 Jupyter iPython 时遇到了一些困难。奇怪的是,以前还能这样,现在好像坏掉了。奇怪的是,这只是我 Mac 书中的新行为。这在我的电脑上的 Jupyter iPython 中仍然有效。我怀疑我的设置有问题,但我不确定如何进一步诊断它。
首先,我能够连接到 Mac 运行 上的 API 以下 .py 文件:
from evernote.api.client import EvernoteClient
dev_token = "my_dev_token_here"
client = EvernoteClient(token=dev_token)
noteStore = client.get_note_store()
nbs= noteStore.listNotebooks()
for nb in nbs: print nb.name
我得到了预期的输出——我的 Evernote 笔记本列表。
接下来,我尝试在 ipython CLI 实例中发出这些命令。我收到以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-3796a38811af> in <module>()
----> 1 ns = client.get_note_store()
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/api/client.pyc in get_note_store(self)
66 def get_note_store(self):
67 user_store = self.get_user_store()
---> 68 note_store_uri = user_store.getNoteStoreUrl()
69 store = Store(self.token, NoteStore.Client, note_store_uri)
70 if not store: # Trick for PyDev code completion
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/api/client.pyc in delegate_method(*args, **kwargs)
136 return functools.partial(
137 targetMethod, authenticationToken=self.token
--> 138 )(**dict(zip(arg_names, args)))
139 else:
140 return targetMethod(*args, **kwargs)
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/edam/userstore/UserStore.pyc in getNoteStoreUrl(self, authenticationToken)
910 - authenticationToken
911 """
--> 912 self.send_getNoteStoreUrl(authenticationToken)
913 return self.recv_getNoteStoreUrl()
914
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/evernote/edam/userstore/UserStore.pyc in send_getNoteStoreUrl(self, authenticationToken)
919 args.write(self._oprot)
920 self._oprot.writeMessageEnd()
--> 921 self._oprot.trans.flush()
922
923 def recv_getNoteStoreUrl(self, ):
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/thrift/transport/THttpClient.pyc in _f(*args, **kwargs)
123 orig_timeout = socket.getdefaulttimeout()
124 socket.setdefaulttimeout(args[0].__timeout)
--> 125 result = f(*args, **kwargs)
126 socket.setdefaulttimeout(orig_timeout)
127 return result
/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg/thrift/transport/THttpClient.pyc in flush(self)
148 self.__http.putheader('Content-Length', str(len(data)))
149 for key, value in self.__headers.iteritems():
--> 150 self.__http.putheader(key, value)
151 self.__http.endheaders()
152
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.pyc in putheader(self, header, *values)
1033 for one_value in values:
1034 if _is_illegal_header_value(one_value):
-> 1035 raise ValueError('Invalid header value %r' % (one_value,))
1036
1037 hdr = '%s: %s' % (header, '\r\n\t'.join(values))
ValueError: Invalid header value 'en-devtoken:V=2 / 1.23; Python / 2.7.11 (default, Jan 22 2016, 08:29:18) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)];'
当 运行 Jupyter iPython 笔记本中的代码时,我得到了类似的结果。感谢您提供任何线索。
必须在最新的 SDK 1.25.2 上修复 Invalid header value
错误。请升级SDK后重试