Connect with the cookie / CHALLENGE error
Hi all,
Hope you are all well !
I was wondering if we could bypass the CHALLENGE error like described in this repository: https://github.com/jqueguiner/lk_scraper#retrieving-cookie
That would be awesome.
Cheers, X
@x0rzkov this is interesting. Has this worked for you? I'd be willing to give it a shot 🙌
Yes, it is working. It avoids the captcha.
Hi,
Hope you are all well !
When do you think you gonna implement the "LI_AT" cookie option ?
Cheers, X
Hi,
Hope you are all well !
When do you think you gonna implement the "LI_AT" cookie option ?
Cheers, X
@tomquirk It will take away alot of pain of getting Challenge exception.
Hi,
Hope you are all well !
When do you think you gonna implement the "LI_AT" cookie option ?
Cheers, X
Here's a documented example from a previous merge request to use to cookies to authenticate : https://github.com/tomquirk/linkedin-api/pull/102/commits/980799f24e7e6181e927ae8a7da60e88b297a461.
I think this documentation was overwritten by another merge/commit at some point but the code is still in the master
P.S: When I did this merge request, I added the JSESSIONID cookie which I think is used for the csrf token. I'm not sure if this is a mandatory one ?? I'd be interested to know this since the JSESSIONID last for ~3months whereas the LI_AT is valid for ~1year I believe
@malhotraguy @x0rzkov @crouinicrouina, I'm looking into this now.
So when we authenticate, we store the whole cookie file, which should already include li_at.
Is this issue for adding a parameter to the Linkedin class that accepts an li_at? In which case, I think @crouinicrouina gave a great explanation on how to achieve this with custom cookies.
Let me know if I have missed something.
You should be able to connect with cookies using either one of these methods
import pickle
# This .jr file is created once you do your first call using the LinkedIn API
with open("./my_custom_cookie.jr", "rb") as f:
cookies = pickle.load(f) # You can use the values from these cookies to use the second method
linkedin = Linkedin("", "", cookies=cookies)
profile = linkedin.get_profile('tom-quirk')
from requests.cookies import cookiejar_from_dict
cookies = cookiejar_from_dict(
{
"liap": "true",
"li_at": os.environ["LINKEDIN_COOKIE_LI_AT"],
"JSESSIONID": os.environ["LINKEDIN_COOKIE_JSESSIONID"],
}
)
linkedin = Linkedin("", "", cookies=cookies)
profile = linkedin.get_profile('tom-quirk')
I'm interested to know whether it works the same with/without the LINKEDIN_COOKIE_JSESSIONID
@tomquirk
Why don't you check the cookies from COOKIE_PATH = os.path.join(LINKEDIN_API_USER_DIR, "cookies/") ?
In my case, saved at:
C:\Program Files\Python38\lib\site-packages\linkedin_api\cookie_repository.py
import os
from pathlib import Path
HOME_DIR = str(Path.home())
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
LINKEDIN_API_USER_DIR = os.path.join(HOME_DIR, ".linkedin_api/")
COOKIE_PATH = os.path.join(LINKEDIN_API_USER_DIR, "cookies/")
It would avoid this right?
import pickle
# This .jr file is created once you do your first call using the LinkedIn API
with open("./my_custom_cookie.jr", "rb") as f:
cookies = pickle.load(f) # You can use the values from these cookies to use the second method
linkedin = Linkedin("", "", cookies=cookies)
profile = linkedin.get_profile('tom-quirk')
Hi all,
Please follow up with using this script https://github.com/everping/Linkedin-Authentication-Challenge to pass the challenge, and once it passed the Linkedin auth will work properly.
@muhammad-mamdouh I ran that script and entered my pin, and the script finished. But then I tried to use this repo's LI API and I'm still getting a challenge exception
How did you solved this @himat ?