Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API stopped working with struct.error: unpack requires a buffer of 1 bytes #27

Open
alekthebear opened this issue Jun 4, 2020 · 24 comments · Fixed by djudman/evernote-telegram-bot#28

Comments

@alekthebear
Copy link

I've had a long running job using the evernote python 3 API. It suddenly stopped working today. I am seeing the following errors:

Traceback (most recent call last):
  File "EDAMTest.py", line 49, in <module>
    UserStoreConstants.EDAM_VERSION_MINOR
  File "/Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.7/site-packages/evernote/api/client.py", line 161, in delegate_method
    return targetMethod(*args, **kwargs)
  File "/Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.7/site-packages/evernote/edam/userstore/UserStore.py", line 491, in checkVersion
    return self.recv_checkVersion()
  File "/Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.7/site-packages/evernote/edam/userstore/UserStore.py", line 504, in recv_checkVersion
    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
  File "/Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 145, in readMessageBegin
    type = self.readByte()
  File "/Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 201, in readByte
    val, = unpack('!b', buff)
struct.error: unpack requires a buffer of 1 bytes

Digging around random stack traces show that :

> /Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.7/site-packages/thrift/protocol/TBinaryProtocol.py(145)readMessageBegin()
-> type = self.readByte()
(Pdb) l
140         else:
141           if self.strictRead:
142             raise TProtocolException(type=TProtocolException.BAD_VERSION,
143                                      message='No protocol version header')
144           name = self.trans.readAll(sz)
145  ->       type = self.readByte()
(Pdb) name
b'ctype html><html lang="en"><head><title>HTTP Status 400 \xe2\x80\x93 Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 \xe2\x80\x93 Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Apache Tomcat/8.5.54</h3></body></html>'

Is the API no longer worker or deprecated?

@ooke
Copy link

ooke commented Jun 4, 2020

I have the same problem, it just stopped working today, reproducible for me with python3.7 and python3.8.

@mitchelljustin
Copy link

mitchelljustin commented Jun 4, 2020

I think i've found the reason for this error. My hypothesis is that Evernote recently updated their API to throw an error for HTTP requests with duplicate Host headers. As it turns out, this Python 3 package duplicates the Host header for some requests. The result is this really obscure error.

When I monkey patch the Thrift HTTP code to dedupe Host headers, my code works again.

@mitchelljustin
Copy link

Found out it's because this SDK uses a (really) old version of thrift. The duplicate host problem in Thrift was seemingly fixed in apache/thrift@760511f#comments, 3.5 years ago

@heart5
Copy link

heart5 commented Jun 4, 2020

I think i've found the reason for this error. My hypothesis is that Evernote recently updated their API to throw an error for HTTP requests with duplicate Host headers. As it turns out, this Python 3 package duplicates the Host header for some requests. The result is this really obscure error.

When I monkey patch the Thrift HTTP code to dedupe Host headers, my code works again.

How can I fixed it like yours. Thank you very much.

@mitchelljustin
Copy link

mitchelljustin commented Jun 4, 2020

Here's a gist with the monkey patch https://gist.github.com/mitchelljustin/46e5ce3e0ddfb2ee154ac9a6ee696ac1

Note, to be proper this SDK should be forked and updated to a later version of Thrift. I tried that but got all kinds of other errors I didn't want to fix. Unfortunately Evernote doesn't maintain this repo anymore.

@iafan
Copy link

iafan commented Jun 5, 2020

This is Evernote speaking. Thanks for reporting this issue! Our engineers are working on a solution, and we will report here when the update is available.

@zonabi
Copy link
Contributor

zonabi commented Jun 10, 2020

Hey everyone. Thanks for your patience and info. (@mitchelljustin was on the money) We have just merged a patch for this, please let me know that it solves the issue or if any calls are still failing.

@heart5
Copy link

heart5 commented Jun 11, 2020

Hey everyone. Thanks for your patience and info. (@mitchelljustin was on the money) We have just merged a patch for this, please let me know that it solves the issue or if any calls are still failing.

It works fine, great. Thanks for members.

@KostyaEsmukov
Copy link

@zonabi Thanks for the merge! Would it be possible to make a new release on pypi?

@zonabi
Copy link
Contributor

zonabi commented Jun 15, 2020

@KostyaEsmukov a new version of the evernote3 package has been released on PyPI (1.25.14)

Let us know if you run into any more issues.

@KostyaEsmukov
Copy link

@zonabi Perfect, thank you! I can confirm that the uploaded version works.

@TristanH
Copy link

TristanH commented Apr 13, 2021

Hiya @zonabi @iafan this issue seems to be happening once again, even on the new version of this package

Notably, it is not happening in sandbox mode, but IS happening in production.

In case it's useful, we have thousands of users who depend on our integration with Evernote, and right now it's completely broken for all of them.

@TristanH
Copy link

TristanH commented Apr 13, 2021

Here's a stack trace:

  File "home/main/integrations/evernote.py", line 35, in prepare_export
    self.note_store = self.client.get_note_store()
  File "home/venv/lib/python3.8/site-packages/evernote/api/client.py", line 106, in get_note_store
    note_store_uri = user_store.getNoteStoreUrl()
  File "home/venv/lib/python3.8/site-packages/evernote/api/client.py", line 165, in delegate_method
    return functools.partial(
  File "home/venv/lib/python3.8/site-packages/evernote/edam/userstore/UserStore.py", line 1156, in getNoteStoreUrl
    return self.recv_getNoteStoreUrl()
  File "home/venv/lib/python3.8/site-packages/evernote/edam/userstore/UserStore.py", line 1167, in recv_getNoteStoreUrl
    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
  File "home/venv/lib/python3.8/site-packages/thrift/protocol/TBinaryProtocol.py", line 145, in readMessageBegin
    type = self.readByte()
  File "home/venv/lib/python3.8/site-packages/thrift/protocol/TBinaryProtocol.py", line 201, in readByte
    val, = unpack('!b', buff)
struct.error: unpack requires a buffer of 1 bytes

@TristanH
Copy link

Looks like the getNoteStoreUrl requests are returning this error:

L><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD><BODY>\n<H1>Access Denied</H1>\n \nYou don\'t have permission to access "http&#58;&#47;&#47;www&#46;evernote&#46;com&#47;edam&#47;user" on this server.<P>\nReference&#32;&#35;18&#46;7937b9d0&#46;1618283633&#46;f8c4dd1\n</BODY>\n</HTML>\n

This request is the same as it was yesterday, but broken now -- so probably a change to the evernote api to improperly return Access Denied?

@heart5
Copy link

heart5 commented Apr 13, 2021

Hiya @zonabi @iafan this issue seems to be happening once again, even on the new version of this package

Notably, it is not happening in sandbox mode, but IS happening in production.

In case it's useful, we have thousands of users who depend on our integration with Evernote, and right now it's completely broken for all of them.

It's seems sites have change the permission for API

@duguguiyu
Copy link

The same error, when i call getNoteStoreUrl

@rdhyee
Copy link

rdhyee commented Apr 13, 2021

I'm seeing the same problem this morning. Trying to get the attention of Evernote Support: https://twitter.com/rdhyee/status/1381977939072311297

I just reported the issue with Evernote -- it's been filed as Ticket# 3296044

@zonabi
Copy link
Contributor

zonabi commented Apr 13, 2021

Evernote engineer here, acknowledging these issues. We are looking into it.

@TristanH
Copy link

@zonabi some other stuff from my debugging, in case it's useful:

  • The javascript sdk doesn't seem to have this issue, but the python2 sdk does
  • other requests on UserStore like checkVersion are broken, but requests to NoteStore like getNotebook and createNote seem to be working fine

@zonabi
Copy link
Contributor

zonabi commented Apr 13, 2021

@TristanH @heart5 @rdhyee @duguguiyu the issue should be resolved now, please let us know if that is not the case!

@rdhyee
Copy link

rdhyee commented Apr 13, 2021

@zonabi My application works again -- thank you!

@TristanH
Copy link

@zonabi yes! Seems to be fixed. Thanks for the quick turnaround :)))

@alekthebear
Copy link
Author

alekthebear commented Jan 8, 2023

Update: Fixed as of 1/10/23

Running into the same issue as #27 (comment) (Access Denied) once again

Stacktrace:

  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/evernote/api/client.py", line 106, in get_note_store
    note_store_uri = user_store.getNoteStoreUrl()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/evernote/api/client.py", line 165, in delegate_method
    return functools.partial(
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/evernote/edam/userstore/UserStore.py", line 1156, in getNoteStoreUrl
    return self.recv_getNoteStoreUrl()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/evernote/edam/userstore/UserStore.py", line 1167, in recv_getNoteStoreUrl
    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/thrift/protocol/TBinaryProtocol.py", line 145, in readMessageBegin
    type = self.readByte()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/thrift/protocol/TBinaryProtocol.py", line 201, in readByte
    val, = unpack('!b', buff)
struct.error: unpack requires a buffer of 1 bytes

Debug info:

> /Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.9/site-packages/evernote/edam/userstore/UserStore.py(1167)recv_getNoteStoreUrl()
   1165 
   1166   def recv_getNoteStoreUrl(self, ):
-> 1167     (fname, mtype, rseqid) = self._iprot.readMessageBegin()
   1168     if mtype == TMessageType.EXCEPTION:
   1169       x = TApplicationException()

ipdb> d
> /Users/xxxxx/Applications/miniconda3/envs/xxxxx/lib/python3.9/site-packages/thrift/protocol/TBinaryProtocol.py(145)readMessageBegin()
    143                                  message='No protocol version header')
    144       name = self.trans.readAll(sz)
--> 145       type = self.readByte()
    146       seqid = self.readI32()
    147     return (name, type, seqid)

ipdb> l
    140     else:
    141       if self.strictRead:
    142         raise TProtocolException(type=TProtocolException.BAD_VERSION,
    143                                  message='No protocol version header')
    144       name = self.trans.readAll(sz)
--> 145       type = self.readByte()
    146       seqid = self.readI32()
    147     return (name, type, seqid)
    148 
    149   def readMessageEnd(self):
    150     pass

ipdb> name
b'L><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD><BODY>\n<H1>Access Denied</H1>\n \nYou don\'t have permission to access "http&#58;&#47;&#47;www&#46;evernote&#46;com&#47;edam&#47;user" on this server.<P>\nReference&#32;&#35;18&#46;2dca4d17&#46;1673189791&#46;f0dd35d4\n</BODY>\n</HTML>\n'

@manjurulhoque
Copy link

Facing the same issue again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.