-1
筆記本或命令行中使用Evernote Python API和Jupyter iPython有些困難。奇怪的是,我過去能夠做到這一點,但現在它似乎被打破了。怪異的部分是這只是我的MacBook上的新行爲。這仍然適用於我的PC上的Jupyter iPython。我懷疑我的設置中有些東西已經壞了,但我不確定如何進一步診斷。在Mac上使用Jupyter iPython時收到的Evernote Python API「無效的標頭值」驗證錯誤
首先,我是能夠連接到運行以下.py文件在Mac上的API:
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的筆記本電腦的代碼時得到了類似的結果。感謝您提供的任何線索。
所以事實證明我已經升級到1.25.2,但是Python在新版本之前的版本中找到了舊版本1.23.2。刪除/usr/local/lib/python2.7/site-packages/evernote-1.23.2-py2.7.egg文件解決了問題。謝謝! – wolfins