LINE
LINE copied to clipboard
"You need to login first. There is no valid certificate": Only Occurs When I Send Group Messages
I have made a nice bot with this that works well. How long are y'all able to keep your programs up without rerunning it? I have to restart the program every hour or I get "You need to login first. There is no valid certificate."
24/7. It runs "forever" now.
That error message is from updateAuthToken failing to do its job, because theres no certificate. It seems like you logged in with an authToken.
How did you get your authToken? When you get authToken, it also creates a ".line.crt" file. Place that inside your .py directory and inside your python binary directory (not sure which will be used. just do both lol)
If you're hosting it in heroku, it cant create that file. You'll have to edit api.py to save the certificate in a heroku global variable or in a table in postgresql, instead of writing it in ".line.crt", and load certificate from where you saved it. The certificate is a string/text.
When you login with authToken only, your client is missing : -id (email) -password -certificate -provider
You may want to provide them. Just add them like client.id = " [email protected]" see api.py for setting client.provider
The "provider" field tells the client if your id is an id or an email
Hey, thanks for the update. A lot of good info there. I'm running the beta of my bot in cmd. I have it login with the email and pw associated with the account. Client variable stays equal to that when the code reruns every 3 minutes. The program is saved in my LINE folder within python27, the certificate is there as well.
Can I pm you a picture of how I have it setup (it's a very small one page program) to see if you can see a quick fix? I appreciate the help.
On Sat, Jun 3, 2017 at 3:23 AM, Muhammad Rizqi Nur <[email protected]
wrote:
24/7. It runs "forever" now.
That error message is from updateAuthToken failing to do its job, because theres no certificate. It seems like you logged in with an authToken.
How did you get your authToken? When you get authToken, it also creates a ".line.crt" file. Place that inside your .py directory and inside your python binary directory (not sure which will be used. just do both lol)
If you're hosting it in heroku, it cant create that file. You'll have to edit api.py to save the certificate in a heroku global variable or in a table in postgresql, instead of writing it in ".line.crt", and load certificate from where you saved it. The certificate is a string/text.
When you login with authToken only, your client is missing : -id (email) -password -certificate -provider
You may want to provide them. Just add them like client.id = " [email protected]" see api.py for setting client.provider
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/carpedm20/LINE/issues/115#issuecomment-305960443, or mute the thread https://github.com/notifications/unsubscribe-auth/AT26G_ARZ9p6oK4sDsR8yp_o9Te-N1JMks5sARgLgaJpZM4Nu7Db .
Here I'll just explain it here. So it runs in cmd, the program is saved in the line directory within python 27, same with my certification. Code framework is:
client=(email,pw)
s=sched.scheduler(time.time, time.sleep) def do_something: if xxxx=true: friend=client.contacts friendsendMessage(....) s.enter(timed schedule, 1, do_something, (sc) s.enter(timed schedul, 1, do_something(s,)) s.run()
That's what I have it set to now, I've also tried having it login again within the if statement (only email and pw). With both, it will work for a few true statements and then eventually give me the error. Do I need to remove or move the login from somewhere or possibly save auth within the program?
On Sat, Jun 3, 2017 at 9:11 PM, Rich Davis [email protected] wrote:
Hey, thanks for the update. A lot of good info there. I'm running the beta of my bot in cmd. I have it login with the email and pw associated with the account. Client variable stays equal to that when the code reruns every 3 minutes. The program is saved in my LINE folder within python27, the certificate is there as well.
Can I pm you a picture of how I have it setup (it's a very small one page program) to see if you can see a quick fix? I appreciate the help.
On Sat, Jun 3, 2017 at 3:23 AM, Muhammad Rizqi Nur < [email protected]> wrote:
24/7. It runs "forever" now.
That error message is from updateAuthToken failing to do its job, because theres no certificate. It seems like you logged in with an authToken.
How did you get your authToken? When you get authToken, it also creates a ".line.crt" file. Place that inside your .py directory and inside your python binary directory (not sure which will be used. just do both lol)
If you're hosting it in heroku, it cant create that file. You'll have to edit api.py to save the certificate in a heroku global variable or in a table in postgresql, instead of writing it in ".line.crt", and load certificate from where you saved it. The certificate is a string/text.
When you login with authToken only, your client is missing : -id (email) -password -certificate -provider
You may want to provide them. Just add them like client.id = " [email protected]" see api.py for setting client.provider
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/carpedm20/LINE/issues/115#issuecomment-305960443, or mute the thread https://github.com/notifications/unsubscribe-auth/AT26G_ARZ9p6oK4sDsR8yp_o9Te-N1JMks5sARgLgaJpZM4Nu7Db .
Oh, right. I remember that api.py sets client's certificate to whatever it gets when it gets a certificate message. There are two of them if I remember correctly. Sometime it receives an empty certificate and overwrite the old one (or maybe it's just me, cuz my connection sucks)
Make it check if its an empty string (or None) or not before setting.
Also add in LineClient's init to set self.certificate to an empty string or whatever. Just to make sure the variable exists, so it doesnt throw more errors.
Anyway, the client should always have certificate if you are able to login (email/id&pass login creates certs, authToken login needs certs). So the issue must be "the cert got deleted somehow after it logged in"
Sorry my previous comment was wrong. AuthToken login is not missing the certificate, it needs certificate
This program is saved in the same directory as my certificate. I even added my certificate to my path.
The basis of my program is this: it checks a forum for a new message from someone. If a new message is found, it sends the message to every friend and every group I'm in. The bot sends about 10-15 messages in one push. If the forums are very active it will send maybe 100 messages an hour.
Is it that I'm pushing too many messages? And with the code framework I detailed above, do you see any reason why that wouldn't work?
On Sun, Jun 4, 2017 at 9:11 AM, Muhammad Rizqi Nur <[email protected]
wrote:
Oh, right. I remember that api.py sets client's certificate to whatever it gets when it gets a certificate message. There are two of them if I remember correctly. Sometime it receives an empty certificate and overwrite the old one (or maybe it's just me, cuz my connection sucks)
Make it check if its an empty string (or None) or not before setting.
Also add in LineClient's init to set self.certificate to an empty string or whatever. Just to make sure the variable exists, so it doesnt throw more errors.
Anyway, the client should always have certificate if you are able to login (email/id&pass login creates certs, authToken login needs certs). So the issue must be "the cert got deleted somehow after it logged in"
Sorry my previous comment was wrong. AuthToken login is not missing the certificate, it needs certificate
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/carpedm20/LINE/issues/115#issuecomment-306042345, or mute the thread https://github.com/notifications/unsubscribe-auth/AT26GzUgeRh-e2JJkL7_dlRRFfgM9txjks5sArsBgaJpZM4Nu7Db .
The error is always from models.py line 68, in sendMessage raise e
Exception: Error: You need to login first. There is no valid certificate.
On Sun, Jun 4, 2017 at 10:16 AM, Rich Davis [email protected] wrote:
And you're talking right here in api.py right? (sorry about all of the messages)
[image: Inline image 1]
On Sun, Jun 4, 2017 at 10:12 AM, Rich Davis [email protected] wrote:
The certificate is here, saved. It hasn't been altered in 3 days.
[image: Inline image 1]
On Sun, Jun 4, 2017 at 10:03 AM, Rich Davis [email protected] wrote:
This program is saved in the same directory as my certificate. I even added my certificate to my path.
The basis of my program is this: it checks a forum for a new message from someone. If a new message is found, it sends the message to every friend and every group I'm in. The bot sends about 10-15 messages in one push. If the forums are very active it will send maybe 100 messages an hour.
Is it that I'm pushing too many messages? And with the code framework I detailed above, do you see any reason why that wouldn't work?
On Sun, Jun 4, 2017 at 9:11 AM, Muhammad Rizqi Nur < [email protected]> wrote:
Oh, right. I remember that api.py sets client's certificate to whatever it gets when it gets a certificate message. There are two of them if I remember correctly. Sometime it receives an empty certificate and overwrite the old one (or maybe it's just me, cuz my connection sucks)
Make it check if its an empty string (or None) or not before setting.
Also add in LineClient's init to set self.certificate to an empty string or whatever. Just to make sure the variable exists, so it doesnt throw more errors.
Anyway, the client should always have certificate if you are able to login (email/id&pass login creates certs, authToken login needs certs). So the issue must be "the cert got deleted somehow after it logged in"
Sorry my previous comment was wrong. AuthToken login is not missing the certificate, it needs certificate
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/carpedm20/LINE/issues/115#issuecomment-306042345, or mute the thread https://github.com/notifications/unsubscribe-auth/AT26GzUgeRh-e2JJkL7_dlRRFfgM9txjks5sArsBgaJpZM4Nu7Db .
Okay this is very weird. So I tested today running code on an 80 second interval sending a "test" message to only friends. It worked fine every 80 seconds for a full hour. I then went back to my program for sending blast messages to groups. It sent the message to all of the groups and then signed me out ended the cmd session. What is going on here? @R-N
Yes, the .line.crt isnt altered.
What I meant is the certificate in the LineClient object. self.certificate There are two piece of code in apy.py which sets that, one of them writes .line.crt, one doesnt.
I dont think it throws certificate error in sendMessage. Must be a chain from updateAuthToken. (Try-except-raise). I remember it will try to updateAuthToken if it gets a TalkException that means the authToken has expired
Yep. sendMessage in models.py has these lines :
except Exception as e: raise e
God knows what it's for.
Here is the framework for the code:
This same code allows messages to contacts to be looped. However, when I change it to groups, like above, it sends the message and then doesn't loop giving the error from line 68 of models.py.
Why does sendmessage allow contacts to be looped but not groups? I'm trying to have my bot send messages to the groups it is in. On Sun, Jun 4, 2017 at 4:30 PM Muhammad Rizqi Nur [email protected] wrote:
Yes, the .line.crt isnt altered.
What I meant is the certificate in the LineClient object. self.certificate There are two piece of code in apy.py which sets that, one of them writes .line.crt, one doesnt.
I dont think it throws certificate error in sendMessage. Must be a chain from updateAuthToken. (Try-except-raise). I remember it will try to updateAuthToken if it gets a TalkException that means the authToken has expired
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/carpedm20/LINE/issues/115#issuecomment-306068294, or mute the thread https://github.com/notifications/unsubscribe-auth/AT26G4vDHXXJuUvpz1MY5VfeawkcG5OPks5sAyHZgaJpZM4Nu7Db .
Try to search for the error message in this api, only updateAuthToken throws that
See what caused it, and what may caused that cause.
In my case it was that the LineClient.certificate became empty somehow after I logged in. No, .line.crt isnt altered at all.
Here's the code that code:
Have you tried my suggestion though? To check if the cert message isnt empty first before setting that as its certificate in api.py
@R-N That's the thing, I don't have to restart pin validation everytime I run the program. I can go to cmd and simply type in "file".py and it reruns.
Here is what my API.py looks like
Let me make myself clear,
I dont think it has anything to do with how you use the api. It's a problem within the api itself.
The fault isnt in your code.
I know bud, I just don't know exactly how to update api.py to make it work to send messages to groups. I think I blasted too many group messages the first day I got it running and that's why it's stopped. I didn't even know what python was until last week.
Wait, so you're logging in with authToken afterall. Why would you even do that (recreating the client)
Try putting this after the "client=LineClient(authToken=authToken)"
print(client.certificate)
Also have you tried my damn suggestion yet? The checking cert thing.
Look for "self.certificate =" in api.py Make sure it doesnt set self.certificate to empty string or None
So @R-N , do I just "certificate= .line.crt" in the api.py? or do I keep it empty as ""?
Sorry buddy, I'm awful with this stuff :/
Oh sorry, you couldve said that youbdidnt understand earlier lol.
You blasting messages make the authToken expire. The client is trying to update it but fails to do so
Wait up ill take a look in the code.
Thank you buddy, it's very helpful.
I just want to be clear, it never asks me for pin validation again when I rerun the code.
Yeah, that's weird. I think I needed to do pincode validation everytime I login with email & password. But well its been a long time since then, maybe I'm mistaken.
Change these lines : if msg.type == 1: self.certificate = msg.certificate self.authToken = self._headers['X-Line-Access'] = msg.authToken
To : if msg.type == 1: If msg.certificate is not None and msg.certificate.strip(): self.certificate = msg.certificate self.authToken = self._headers['X-Line-Access'] = msg.authToken
Sorry for the bad indentation, I'm on phone
Only "self.certificate = msg.certificate" should be in the new if statement
Does this look correct?
(sorry about the sideways images, my snipping tool doesn't display code in python for some reason)