What is error code 35, returned by the telegram.org server
<p>My client often receives the following message container from the telegram server, seemingly at random:</p>

<pre><code>{'MessageContainer': [{'msg': {u'bad_msg_notification': {u'bad_msg_seqno': 4, u'bad_msg_id': 6330589643093583872L, u'error_code': 35}}, 'seqno': 4, 'msg_id': 6330589645303624705L}, {'msg': {u'msgs_ack': {u'msg_ids': [6330589643093583872L]}}, 'seqno': 4, 'msg_id': 6330589645303639041L}]})
</code></pre>

<p>You may notice: <strong>'error code': 35</strong> above, but there is no description of what that error code means. So far I have been ignoring it but that is not a good long term solution IMHO. Any ideas what that error code means?</p>

<p>There are a set of errors associated with <strong><em>bad_msg_seqno</em></strong> </p>

<p><strong>From the documentation:</strong> </p>

<blockquote>
  <p>Here, error_code can also take on the following values:</p>
  
  <ol start="32">
  <li>msg_seqno too low (the server
  has already received a message with a lower msg_id but with either a
  higher or an equal and odd seqno)</li>
  <li>msg_seqno too high (similarly,
  there is a message with a higher msg_id but with either a lower or
  an equal and odd seqno)</li>
  <li>an even msg_seqno expected (irrelevant
  message), but odd received</li>
  <li>odd msg_seqno expected (relevant
  message), but even received</li>
  </ol>
</blockquote>

<p><strong>Formal Definition:</strong> <a href="https://core.telegram.org/mtproto/description#message-sequence-number-msg-seqno" rel="nofollow">Message Sequence Number (msg_seqno)</a></p>

<blockquote>
  <p>a 32-bit number equal to twice the number of âcontent-relatedâ
  messages (those requiring acknowledgment, and in particular those that
  are not containers) created by the sender prior to this message and
  subsequently incremented by one if the current message is a
  content-related message. A container is always generated after its
  entire contents; therefore, its sequence number is greater than or
  equal to the sequence numbers of the messages contained in it.</p>
</blockquote>

<p><strong>Notes:</strong></p>

<ol>
<li>Every new session starts from seq_no = 1 --> (0 * 2) + 1</li>
<li>Every sequence number you send is calculated as: (number_of_content_messages_ already_sent * 2) + 1 hence the all sequence numbers you send are always odd</li>
<li>A container messages seq_no == the max seq_no of its content messages</li>
<li>The server will always reply you with the correct <code>server_seq_no</code> which should be 1 greater than your <strong><em>correct</em></strong> max seq_no so far.</li>
<li>hence a good check / seq_no correction scheme would be to use the latest received <code>server_seq_no</code> (which should always be even) to confirm what your <code>current-expected</code> seq_no should be, and adjust as required.</li>
</ol>

<p>The above technique has worked for me in avoiding these intermittent error messages completely.</p>

python api telegram