ianding1 / leetcode.vim

Solve LeetCode problems in Vim!
MIT License
312 stars 43 forks source link

New way to overcome new auth way? #25

Closed zhoupro closed 4 years ago

zhoupro commented 4 years ago

image

I stole cookie from firefox, Now It can works.

def getcookiefromchrome(host='.oschina.net',cookiepath='/data/www/cookie'):
    sql="select host,name,value from moz_cookies where host='%s'" % host
    with sqlite3.connect(cookiepath) as conn:
        cu=conn.cursor()
        cookies={name:value for host,name,value in cu.execute(sql).fetchall()}
        return cookies

def signin(username, password):
    global session
    session = requests.Session()
    if 'cn' in LC_BASE:
        cookie = getcookiefromchrome('.leetcode.cn',cookiepath='/data/www/cookie')
        res = session.get(LC_CSRF)
    else:
        cookie = getcookiefromchrome('.leetcode.com',cookiepath='/data/www/cookie')
        res = session.get(LC_LOGIN)

    session.cookies = requests.utils.add_dict_to_cookiejar(session.cookies, cookie)

    if res.status_code != 200:
        _echoerr('cannot open ' + LC_BASE)
        return False

    return True
ianding1 commented 4 years ago

That looks fantastic! Could you check if you can use browser-cookies3? Chrome users might need it.

zhoupro commented 4 years ago

First of all, I use this plugin in windows10's wsl's docker's ubuntu. I need python to stolen cookie from windows format of cookies.sqlite3. I try Chrome fisrt, Chrome cookie's value is encode which depends python package which only run in windows. Sencond, I looked into browser-cookies3 source, If your plugin env is same as your Chrome or Firefox, I works fine. If not, It does't function well. Finally, I choose Firefox, because it's format is cross platform.

ianding1 commented 4 years ago

New commit should have solved this problem.

Thank you for the tip!

tenfyzhong commented 4 years ago

Vim throws errors use firefox.

image

environment os: macos 10.14.5 vim: 8.1 with patches 1-2350 python: 3.7.5 keyring: 21.0.0 browser-cookie3: 0.9.1

steve-jokes commented 4 years ago

First of all, I use this plugin in windows10's wsl's docker's ubuntu. I need python to stolen cookie from windows format of cookies.sqlite3. I try Chrome fisrt, Chrome cookie's value is encode which depends python package which only run in windows. Sencond, I looked into browser-cookies3 source, If your plugin env is same as your Chrome or Firefox, I works fine. If not, It does't function well. Finally, I choose Firefox, because it's format is cross platform.

another wsl user is here, :P is there other method to login without browser-cookie3?

zhngjan commented 4 years ago

That's great. I just update plugin, and it works.