Failed to get current state: AuthKeyUnregisteredError('The key is not registered in the system') - telethon

I am using Telethon to connect to Telegram and pull down some messages to run analytics on. I wrote the original code in 2018 and it worked perfectly. It connected, read from the channel and allowed me to read messages as I expected. Recently I tried running the script again and it now keeps asking me for my phone number and authentication code despite the fact the session file has been created. In the past I only was asked for the phone number and authentication code once, then the session file was created and I did not have to repeat myself. Now I find myself doing it every time I run the program.
I should note that readChannel.session is created in my local directory and has following properties
$ file readChannel.session
readChannel.session: SQLite 3.x database, last written using SQLite version 3021000
I enabled logging and got the following
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168064255177608 to InvokeWithLayerRequest (3601b10)
DEBUG:telethon.network.mtprotolayer:Packed 1 message(s) in 68 bytes for sending
INFO:telethon.network.mtprotosender:Broken authorization key; resetting
DEBUG:telethon.network.mtprotosender:Closing current connection...
DEBUG:telethon.network.mtprotosender:Awaiting for the send loop before reconnecting...
DEBUG:telethon.network.mtprotosender:Awaiting for the receive loop before reconnecting...
DEBUG:telethon.network.mtprotosender:Closing current connection...
INFO:telethon.network.mtprotosender:Connecting to 149.154.167.92:443/TcpFull...
DEBUG:telethon.network.mtprotosender:Connection attempt 1...
DEBUG:telethon.network.mtprotosender:Connection success!
DEBUG:telethon.network.mtprotosender:New auth_key attempt 1...
DEBUG:telethon.network.mtprotosender:Starting send loop
DEBUG:telethon.network.mtprotosender:Starting receive loop
INFO:telethon.network.mtprotosender:Connection to 149.154.167.92:443/TcpFull complete!
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
INFO:telethon.client.updates:Asking for the current state after reconnect...
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168067804342024 to InvokeWithLayerRequest (3601b10)
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168067820286504 to GetStateRequest (3601f50)
DEBUG:telethon.network.mtprotolayer:Packed 2 message(s) in 112 bytes for sending
DEBUG:telethon.network.mtprotosender:Handling bad salt for message 6755168067844913236
DEBUG:telethon.network.mtprotosender:2 message(s) will be resent
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168068088576072 to InvokeWithLayerRequest (3601b10)
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168068116633168 to GetStateRequest (3601f50)
DEBUG:telethon.network.mtprotolayer:Packed 2 message(s) in 112 bytes for sending
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168068176325552 to MsgsAck (394c0f0)
DEBUG:telethon.network.mtprotolayer:Packed 1 message(s) in 36 bytes for sending
DEBUG:telethon.network.mtprotosender:Handling container
DEBUG:telethon.network.mtprotosender:Handling new session created
DEBUG:telethon.network.mtprotosender:Handling acknowledge for [6755168068088576072, 6755168068116633168]
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
DEBUG:telethon.network.mtprotosender:Handling RPC result for message 6755168068116633168
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
INFO:telethon.client.updates:Failed to get current state: AuthKeyUnregisteredError('The key is not registered in the system')
DEBUG:telethon.network.mtprotosender:Handling RPC result for message 6755168068088576072
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168068470441572 to MsgsAck (3601ed0)
DEBUG:telethon.network.mtprotolayer:Packed 1 message(s) in 36 bytes for sending
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168068486387960 to MsgsAck (3601e10)
DEBUG:telethon.network.mtprotolayer:Assigned msg_id = 6755168068510330908 to GetStateRequest (3601d10)
DEBUG:telethon.network.mtprotolayer:Packed 2 message(s) in 112 bytes for sending
DEBUG:telethon.network.mtprotosender:Handling RPC result for message 6755168068510330908
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
Please enter your phone (or bot token):
It would appear the problem relates to INFO:telethon.client.updates:Failed to get current state: AuthKeyUnregisteredError('The key is not registered in the system')
Here is the code
api_id = xxx
api_hash = xxx
channel_name = xxx
client = TelegramClient('readChannel', api_id, api_hash)
# Connect to telegram
try:
client.connect()
client.start()
except:
print ("Could not connect to telegram")
# Connect to channel and get posts
try:
channel_entity=client.get_entity(channel_name)
posts = client(GetHistoryRequest(
peer=channel_entity,
limit=1000000,
offset_date=0,
offset_id=0,
max_id=0,
min_id=0,
add_offset=0,
hash=0))
except:
print ("Could not connect to channel ", channel_name)
Expected: I expected to be asked phone number and authentication code once and then it would read from the session file thereafter.
Actual: Now I find myself doing it every time I run the program (providing my phone number and authentication code).

Related

"Mailbox size limit exceeded" when sending mails on an empty exchange account with MailKit .Net

I am using MimeKit and Mailkit to send emails from my VB.NET application, through my own SMTP server (run on Windows Server 2016, with SmarterMail).
Until then, I was sending emails to info#mywebsite.com which is an alias of infos#mywebsite.com and it worked very well. This email account is a exchange account with more of 49 Gio free.
Since a few days, I've received this error : Mailbox size limit exceeded
When a set a spy on it, this is what I get :
This is the log :
S: 235 Authentication successful
C: MAIL FROM:<info1#mywebsite.com> SIZE=599
S: 250 OK <info1#mywebsite.com> Sender ok
C: RCPT TO:<info#mywebsite.com>
S: 452 <info#mywebsite.com> Mailbox size limit exceeded
C: RSET
S: 250 OK
I don't understand why I get this error while my recipient account is pretty much empty.
When I try to send email from my outlook account to info#mywebsite, I get no error.
When I try to send emails from my code to anothers recipients, I get no error.
My disk space is very large on my mail serveur (almost 2 To).
This is my code :
Dim message As New MimeMessage()
message.From.Add(New MailboxAddress("My website", "info1#mywebsite.com"))
message.To.Add(New MailboxAddress("My website", "info#mywebsite.com"))
message.Subject = "any subject"
Dim builder As New BodyBuilder()
builder.TextBody = textemail
builder.HtmlBody = htmlemail
message.Body = builder.ToMessageBody()
' SERVER SMTP
Using client As New MailKit.Net.Smtp.SmtpClient()
client.ServerCertificateValidationCallback = (Function(sender, certificate, chain, sslPolicyErrors) True)
client.Connect("mail.mysmtpserver.com", 587, MailKit.Security.SecureSocketOptions.None)
client.Authenticate("Mailkit_SMTP_UserName", "Mailkit_SMTP_Password")
client.Send(message)
client.Disconnect(True)
End Using
Thanks a lot for any suggestion (I don't find any related topic on Google)
I've found what was wrong in my SMTP server : Smartermail has it own mailbox size configuration for any mail account, that is limited at 100Mb.
You can change it by going on : your domain > Manage > Account

JSch session hangs when attempting to get connection

I am using com.jcraft.jsch version 0.1.55 and connecting to a number of Linux servers, one at a time. Some server connections are successful, while others are not.
Ostensibly the code in the servers is identical. I need to find out why the different behaviour.
Client code. Set up
JSch jsch = new JSch();
Session session = jsch.getSession("username", ip_address, 22);
session.setPassword("password");
session.setConfig("StrictHostKeyChecking","no");
session.connect()
Hangs on calling UserAuthGSSAPIWithMIC.start()
Working flow:
Session.start()
line 22 super.start(session) sets buf[5] = 51
line 25 this.buf.putByte((byte)50) sets buf[5] = 50
flow continues to line 39 this.buf = session.read(this.buf) which returns
and has set buf[5] to 51 forcing the auth to move on the next auth method.
Eventually succeeds using the password method
Broken flow:
Session.start()
super.start() sets buf[5] = 51
this.buf.putByte((byte)50) sets buf[5] = 50
flow continues to line 39 this.buf = session.read(this.buf) which returns
and has set buf[5] to 60 which sends the code to create a new context,
part of which calls oid.equals() which hangs on line 160 -
return this.oid.equals.((Object) ((Oid) other).oid);
There are no log messages in this part of the code, so no information about what the code is doing.
I can make the problem go away by setting session.setConfig("PreferredAuthentications", "password");
I want to know why the code is hanging on the UserAuthGSSAPIWithMIC on some servers but not others. Also how I can get some informative logging information.

What does USB transfer need status phase?

Basically after every IN, OUT or SETUP transaction we have an ACK/NAK packet at the end of the transaction. If a handshake packet is part of every transfer as it comes after the data packet which is preceded by token packet, then why do we need a status stage? This seems to be present in the control transfer.
In the protocol endpoints are in a status: ACTIVE, HALT, STALL,...
in the status phase this status is determined (GET_STATUS(0x00) request (http://www.beyondlogic.org/usbnutshell/usb6.shtml) )
The status phase check is a bit like a CRC checksum over the entire request not over each single packet.
http://www.beyondlogic.org/usbnutshell/usb4.shtml:
"
Status Stage reports the status of the overall request and this once again varies due to direction of transfer. Status reporting is always performed by the function.
IN: If the host sent IN token(s) during the data stage to receive data, then the host must acknowledge the successful recept of this data. This is done by the host sending an OUT token followed by a zero length data packet. The function can now report its status in the handshaking stage. An ACK indicates the function has completed the command is now ready to accept another command. If an error occurred during the processing of this command, then the function will issue a STALL. However if the function is still processing, it returns a NAK indicating to the host to repeat the status stage later.
OUT: If the host sent OUT token(s) during the data stage to transmit data, the function will acknowledge the successful recept of data by sending a zero length packet in response to an IN token. However if an error occurred, it should issue a STALL or if it is still busy processing data, it should issue a NAK asking the host to retry the status phase later.
"
or see http://wiki.osdev.org/Universal_Serial_Bus
"
Finally, a STATUS transaction from the function to the host indicates whether the [control] transfer was successful.
"

Read kannel DLR errors

I have kannel SMPP (kannel.org) and receive SMS statuses by param: %d
And here is table:
16 = not delivered to smsc
8 = you submitted to smsc. ie smsc tell
kannel he has the msg
4 = msg is in smsc queue. ie smsc tell kannel he queued the msg in its queue.
2 = failed 1 = delivered to phone
But here is very low information. How I can receive more information about (wrong number or something like what)? Now is just failed and whats all, if we want to know why failed we must ask our partners support.
More detailed information on delivery error you can fetch from the following sources:
network_error_code TLV (0x0423) - see p. 5.3.2.31 of SMPP v3.4 specification
text part of DLR message (%A in dlr-url)
command_status in case of rejection (represented as "NACK/$code"
Example of text part in DLR:
id:0832095221 sub:001 dlvrd:000 submit date:1203311115 done date:1204010436 stat:UNDELIV err:011 text:some text here
Here you can see 011 error code in undeliverable message.
However there are many vendor specific issues you need to discover with each new SMSC. And no strict requirements in SMPP specification to information to represented in DLR.
For your DLR URL add this:
dlr_mask=31
dlr_url=....?answer=%A&status=%d
Where DLR bitmask means:
1: Received by phone
2: Failure to deliver to phone
4: Queued for delivery
8: Accepted by other SMSC
16: Rejected by other SMSC
If you get a 16, or your get a 2 it'll look like this:
status=<2 or 16 here>
answer=NACK//
The get a table mapping hex_code to its vendor-specific meaning from the carrier

How to sync for the emails which are received after a particular email.

I am working on an application which download Yahoo account emails in the order of down to top using Yahoo Mail API's.
Application sync logic works like below
Lets say Inbox consists of 1000 emails.
1) Initially fetching 100 emails message ID's by using "ListMessages" with parameters startMid = 0 and numMid=100.
2) Processing chunk emails .
3) Now requesting for the next chunk emails by giving the startMid = 100 and numMid=100.
The above logic works fine if user is not deleting any emails during syncing.
Is there any way to retrieve next chunk emails based on the message ID (string unique value) rather than message number.
What is the logic for syncing the emails from the last processed message?
PS:I can not rely on message number (since message number is not meant for unique identifier of a message).
I was looking for the same thing and found "How to get only emails which are arrived from the Client last sync." (http://developer.yahoo.com/forum/Yahoo-Mail-Web-Services-API/How-to-get-only-emails-which/1320329478746-16f18e6a-aadd-40c3-b259-e095ce80a1e6) where some guy reply "This feature is not available right now but we do plan to support this in future." date: 3 Nov 2011 11:24 AM
I think you can query mailTables (with YQL) or ListMessage (Api) and get the complete list of messages id (without any info) eg: SELECT * FROM ymail.messages WHERE numInfo="0"
And then "count" the position of the last message you got and then, get mail from that number. Eg: SELECT * FROM ymail.messages WHERE startMid="3" and numMid="100"
What do you think?
Greetings from Argentina
PS: sorry about my horrible english