Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] FATA failed to get question data: no cookie found in browser #193

Open
1 task done
zrcoder opened this issue Jun 8, 2023 · 16 comments
Open
1 task done

[Bug] FATA failed to get question data: no cookie found in browser #193

zrcoder opened this issue Jun 8, 2023 · 16 comments
Labels
help wanted Extra attention is needed windows Windows specific issue

Comments

@zrcoder
Copy link

zrcoder commented Jun 8, 2023

Verification steps

leetgo config

language: zh
code:
  lang: go
leetcode:
  site: https://leetcode.cn
#  credentials:
#    from: browser
#editor:
#  use: none

Debug log

2023/06/08 09:39:49 DEBU cache loaded path=/Users/ding/.config/leetgo/cache/leetcode-questions.db time="962.899µs"
2023/06/08 09:39:49 INFO reading cookies from browser domain=leetcode.cn
2023/06/08 09:39:49 DEBU finished read cookies from browser elapsed=9.75268ms
2023/06/08 09:39:49 FATA failed to get question data: no cookie found in browser

Description

I have already login in browser, but the cli cannot get cookie.

The bug both appears on leetcode.cn and leetcode.com

Steps

go install github.com/j178/leetgo@latest
mkdir demo
cd demo
leetgo init -t cn -l go

leetgo pick 1
@j178
Copy link
Owner

j178 commented Jun 8, 2023

May I ask which browser are you using? Currently only standard installation of chrome, edge, safari and firefox are supported.

@zrcoder
Copy link
Author

zrcoder commented Jun 8, 2023

May I ask which browser are you using? Currently only standard installation of chrome, edge, safari and firefox are supported.

chrome

I also tried with safari, still not work.

@zrcoder
Copy link
Author

zrcoder commented Jun 8, 2023

I don't know why, but when I installed firefox and use it to login leetcode, the cli woks~~

@j178
Copy link
Owner

j178 commented Jun 8, 2023

I added some logs in the master branch, can you try

go install github.com/j178/leetgo@master
DEBUG=1 leetgo pick 1

and paste the log here? It may help debugging why leetgo not reading cookies from Chrome. Thanks!

@zrcoder
Copy link
Author

zrcoder commented Jun 8, 2023

I added some logs in the master branch, can you try

go install github.com/j178/leetgo@master
DEBUG=1 leetgo pick 1

and paste the log here? It may help debugging why leetgo not reading cookies from Chrome. Thanks!

seems the new change breaks the configfile format:

2023/06/08 15:56:38 FATA unmarshal config failed: 1 error(s) decoding:

* 'editor.args' expected type 'string', got unconvertible type '[]interface {}', value: '[]'

so I removed ~/.config/leetgo directory and tried from begin.

rm -rf ~/.config/leetgo
mkdir demo
cd demo
leetgo init

I loged in leetcode with chrome
the out put for DEBUG=1 leetgo pick 1is:

2023/06/08 16:01:06 DEBU cache loaded path=/Users/ding/.config/leetgo/cache/leetcode-questions.db time=1.218358ms
2023/06/08 16:01:06 INFO reading cookies from browsers domain=leetcode.com
2023/06/08 16:01:06 DEBU reading cookies browser=safari file=/Users/ding/Library/Cookies/Cookies.binarycookies
2023/06/08 16:01:06 DEBU failed to read cookies error="open /Users/ding/Library/Cookies/Cookies.binarycookies: operation not permitted"
2023/06/08 16:01:06 DEBU reading cookies browser=firefox file="/Users/ding/Library/Application Support/Firefox/Profiles/6idtsv2e.default-1686208684195/cookies.sqlite"
2023/06/08 16:01:06 DEBU no cookie found browser=firefox
2023/06/08 16:01:06 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies"
2023/06/08 16:01:06 DEBU failed to read cookies error="open /Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies: no such file or directory"
2023/06/08 16:01:06 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Cookies"
2023/06/08 16:01:06 DEBU no cookie found browser=chrome
2023/06/08 16:01:06 DEBU finished reading cookies elapsed=14.425779ms
2023/06/08 16:01:06 WARN add credentials failed err="no cookies found in browsers"
2023/06/08 16:01:06 DEBU request method=POST url=https://leetcode.com/graphql
  body=
  │ {"operationName":"questionData","query":"\n\tquery questionData($titleSlug: String!) {\n\t\tquestion(titleSlug: $titleSlug) {\n\t\t\tquestionId\n\t\t\tquestionFrontendId\n\t\t\tcategoryTitle\n\t\t\ttitle\n\t\t\ttitleSlug\n\t\t\tcontent\n\t\t\tisPaidOnly\n\t\t\ttranslatedTitle\n\t\t\ttranslatedContent\n\t\t\tdifficulty\n\t\t\tstatus\n\t\t\tstats\n\t\t\thints\n\t\t\tsimilarQuestions\n\t\t\tsampleTestCase\n\t\t\texampleTestcases\n\t\t\texampleTestcaseList\n\t\t\tmetaData\n\t\t\tcodeSnippets {\n\t\t\t\tlang\n\t\t\t\tlangSlug\n\t\t\t\tcode\n\t\t\t}\n\t\t\ttopicTags {\n\t\t\t\tname\n\t\t\t\tslug\n\t\t\t\ttranslatedName\n\t\t\t}\n\t\t\teditorType\n\t\t}\n\t}","variables":{"titleSlug":"two-sum"}}

2023/06/08 16:01:07 FATA failed to get question data: unexpected status code: 400, body: <empty>

**and this time, firefox also not work ~~**

2023/06/08 16:08:15 DEBU cache loaded path=/Users/ding/.config/leetgo/cache/leetcode-questions.db time=2.707701ms
2023/06/08 16:08:15 INFO reading cookies from browsers domain=leetcode.com
2023/06/08 16:08:15 DEBU reading cookies browser=safari file=/Users/ding/Library/Cookies/Cookies.binarycookies
2023/06/08 16:08:15 DEBU failed to read cookies error="open /Users/ding/Library/Cookies/Cookies.binarycookies: operation not permitted"
2023/06/08 16:08:15 DEBU reading cookies browser=firefox file="/Users/ding/Library/Application Support/Firefox/Profiles/6idtsv2e.default-1686208684195/cookies.sqlite"
2023/06/08 16:08:15 DEBU found cookie browser=firefox
2023/06/08 16:08:15 DEBU finished reading cookies elapsed=21.278037ms
2023/06/08 16:08:15 DEBU request method=POST url=https://leetcode.com/graphql
  body=
  │ {"operationName":"questionData","query":"\n\tquery questionData($titleSlug: String!) {\n\t\tquestion(titleSlug: $titleSlug) {\n\t\t\tquestionId\n\t\t\tquestionFrontendId\n\t\t\tcategoryTitle\n\t\t\ttitle\n\t\t\ttitleSlug\n\t\t\tcontent\n\t\t\tisPaidOnly\n\t\t\ttranslatedTitle\n\t\t\ttranslatedContent\n\t\t\tdifficulty\n\t\t\tstatus\n\t\t\tstats\n\t\t\thints\n\t\t\tsimilarQuestions\n\t\t\tsampleTestCase\n\t\t\texampleTestcases\n\t\t\texampleTestcaseList\n\t\t\tmetaData\n\t\t\tcodeSnippets {\n\t\t\t\tlang\n\t\t\t\tlangSlug\n\t\t\t\tcode\n\t\t\t}\n\t\t\ttopicTags {\n\t\t\t\tname\n\t\t\t\tslug\n\t\t\t\ttranslatedName\n\t\t\t}\n\t\t\teditorType\n\t\t}\n\t}","variables":{"titleSlug":"two-sum"}}

2023/06/08 16:08:15 FATA failed to get question data: unexpected status code: 400, body: <empty>

ps: I cleared cookies on chrome and firefox befor login

@j178
Copy link
Owner

j178 commented Jun 8, 2023

seems the new change breaks the configfile format:

config file format changed in v1.0, here is the release note, which metioned the breaking change: https://github.com/j178/leetgo/releases/tag/v1.0

It seems leetcode.com has changed its API authentication method, I will try to figure it out later. For this issue, can you please test it using leetcode.cn instead?

go install github.com/j178/leetgo@master
leetgo init -f -t cn demo
cd demo
DEBUG=1 leetgo pick 1

After logging in in Chrome, please wait for some time (like 30 seconds) before trying leetgo pick. Chrome seems not to write the cookies immediately.

@zrcoder
Copy link
Author

zrcoder commented Jun 9, 2023

@j178 tried the latest version

Works for FireFox but not for Chrome

leetgo pick 1 works even without login - I think pick needs no credentials, just as the behavior on browser(not login, but can view)
So I picked question 1 and test leetgo test 1:

  1. log in leetcode.cn on browser
  2. leetgo test 1 not work, even though I tried 10min later

output for DEBUG=1 leetgo test 1

2023/06/09 10:02:32 DEBU cache loaded path=/Users/ding/.config/leetgo/cache/leetcode-questions.db time=12.380354ms
2023/06/09 10:02:32 DEBU reading cookies browser=safari file=/Users/ding/Library/Cookies/Cookies.binarycookies
2023/06/09 10:02:32 DEBU failed to read cookies error="open /Users/ding/Library/Cookies/Cookies.binarycookies: operation not permitted"
2023/06/09 10:02:32 DEBU reading cookies browser=firefox file="/Users/ding/Library/Application Support/Firefox/Profiles/6idtsv2e.default-1686208684195/cookies.sqlite"
2023/06/09 10:02:32 DEBU no cookie found browser=firefox
2023/06/09 10:02:32 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies"
2023/06/09 10:02:32 DEBU failed to read cookies error="open /Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies: no such file or directory"
2023/06/09 10:02:32 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Cookies"
2023/06/09 10:02:32 DEBU no cookie found browser=chrome
2023/06/09 10:02:32 DEBU finished reading cookies elapsed=7.346075ms
2023/06/09 10:02:32 INFO running test remotely question=two-sum [email protected]
2023/06/09 10:02:32 DEBU reading cookies browser=safari file=/Users/ding/Library/Cookies/Cookies.binarycookies
2023/06/09 10:02:32 DEBU failed to read cookies error="open /Users/ding/Library/Cookies/Cookies.binarycookies: operation not permitted"
2023/06/09 10:02:32 DEBU reading cookies browser=firefox file="/Users/ding/Library/Application Support/Firefox/Profiles/6idtsv2e.default-1686208684195/cookies.sqlite"
2023/06/09 10:02:32 DEBU no cookie found browser=firefox
2023/06/09 10:02:32 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies"
2023/06/09 10:02:32 DEBU failed to read cookies error="open /Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies: no such file or directory"
2023/06/09 10:02:32 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Cookies"
2023/06/09 10:02:32 DEBU no cookie found browser=chrome
2023/06/09 10:02:32 DEBU finished reading cookies elapsed=2.646027ms
2023/06/09 10:02:32 WARN add credentials failed, continue requesting without credentials err="no cookies found in browsers"
2023/06/09 10:02:32 DEBU request method=POST url=https://leetcode.cn/graphql
  body=
  │ {"operationName":"questionData","query":"\n\tquery questionData($titleSlug: String!) {\n\t\tquestion(titleSlug: $titleSlug) {\n\t\t\tquestionId\n\t\t\tquestionFrontendId\n\t\t\tcategoryTitle\n\t\t\ttitle\n\t\t\ttitleSlug\n\t\t\tcontent\n\t\t\tisPaidOnly\n\t\t\ttranslatedTitle\n\t\t\ttranslatedContent\n\t\t\tdifficulty\n\t\t\tstatus\n\t\t\tstats\n\t\t\thints\n\t\t\tsimilarQuestions\n\t\t\tsampleTestCase\n\t\t\texampleTestcases\n\t\t\texampleTestcaseList\n\t\t\tjsonExampleTestcases\n\t\t\tmetaData\n\t\t\tcodeSnippets {\n\t\t\t\tlang\n\t\t\t\tlangSlug\n\t\t\t\tcode\n\t\t\t}\n\t\t\ttopicTags {\n\t\t\t\tname\n\t\t\t\tslug\n\t\t\t\ttranslatedName\n\t\t\t}\n\t\t\teditorType\n\t\t}\n\t}","variables":{"titleSlug":"two-sum"}}

2023/06/09 10:02:32 DEBU response url=https://leetcode.cn/graphql code=200
  headers=
  │ Connection: keep-alive\r
  │ Content-Length: 9739\r
  │ Content-Type: application/json\r
  data="{\"data\":{\"question\":{\"questionId\":\"1\",\"questionFrontendId\":\"1\",\"categoryTitle\":\"Algorithms\",\"title\":\"Two Sum\",\"titleSlug\":\"two-sum\",\"content\":\"<p>Given an array of integers <code>nums</code>&nbsp;and an integer <code>target</code>, return <em>indices of the two numbers such that they add up to <code>target</code></em>.</p>\n\n<p>You may assume that each input would have <strong><em>exactly</em> one solution</strong>, and you may not use the <em>same</em> element twice.</p>\n\n<p>You can return the answer in any order.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\\"example\\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,7,11,15], target = 9\n<strong>Output:</strong> [0,1]\n<strong>Explanation:</strong> Because nums[0] + nums[1] == 9, we return [0, 1].\n</pre>\n\n<p><strong class=\\"example\\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,2,4], target = 6\n<strong>Output:</strong> [1,2]\n</pre>\n\n<p><strong class=\\"example\\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,3], target = 6\n<strong>Output:</strong> [0,1]\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>\n\t<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>-10<sup>9</sup> &lt;= target &lt;= 10<sup>9</sup></code></li>\n\t<li><strong>Only one valid answer exists.</strong></li>\n</ul>\n\n<p>&nbsp;</p>\n<strong>Follow-up:&nbsp;</strong>Can you come up with an algorithm that is less than&nbsp;<code>O(n<sup>2</sup>)&nbsp;</code>time complexity?\",\"isPaidOnly\":false,\"translatedTitle\":\"\u4e24\u6570\u4e4b\u548c\",\"translatedContent\":\"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 <code>nums</code>&nbsp;\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c <code>target</code>\uff0c\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa <strong>\u548c\u4e3a\u76ee\u6807\u503c </strong><em><code>target</code></em>&nbsp; \u7684\u90a3&nbsp;<strong>\u4e24\u4e2a</strong>&nbsp;\u6574\u6570\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002</p>\n\n<p>\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848\u3002\u4f46\u662f\uff0c\u6570\u7ec4\u4e2d\u540c\u4e00\u4e2a\u5143\u7d20\u5728\u7b54\u6848\u91cc\u4e0d\u80fd\u91cd\u590d\u51fa\u73b0\u3002</p>\n\n<p>\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\\"example\\">\u793a\u4f8b 1\uff1a</strong></p>\n\n<pre>\n<strong>\u8f93\u5165\uff1a</strong>nums = [2,7,11,15], target = 9\n<strong>\u8f93\u51fa\uff1a</strong>[0,1]\n<strong>\u89e3\u91ca\uff1a</strong>\u56e0\u4e3a nums[0] + nums[1] == 9 \uff0c\u8fd4\u56de [0, 1] \u3002\n</pre>\n\n<p><strong class=\\"example\\">\u793a\u4f8b 2\uff1a</strong></p>\n\n<pre>\n<strong>\u8f93\u5165\uff1a</strong>nums = [3,2,4], target = 6\n<strong>\u8f93\u51fa\uff1a</strong>[1,2]\n</pre>\n\n<p><strong class=\\"example\\">\u793a\u4f8b 3\uff1a</strong></p>\n\n<pre>\n<strong>\u8f93\u5165\uff1a</strong>nums = [3,3], target = 6\n<strong>\u8f93\u51fa\uff1a</strong>[0,1]\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>\u63d0\u793a\uff1a</strong></p>\n\n<ul>\n\t<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>\n\t<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>-10<sup>9</sup> &lt;= target &lt;= 10<sup>9</sup></code></li>\n\t<li><strong>\u53ea\u4f1a\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7b54\u6848</strong></li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>\u8fdb\u9636\uff1a</strong>\u4f60\u53ef\u4ee5\u60f3\u51fa\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u5c0f\u4e8e <code>O(n<sup>2</sup>)</code> \u7684\u7b97\u6cd5\u5417\uff1f</p>\n\",\"difficulty\":\"Easy\",\"status\":null,\"stats\":\"{\\"totalAccepted\\": \\"4.5M\\", \\"totalSubmission\\": \\"8.5M\\", \\"totalAcceptedRaw\\": 4519343, \\"totalSubmissionRaw\\": 8548362, \\"acRate\\": \\"52.9%\\"}\",\"hints\":[\"A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations.\",\"So, if we fix one of the numbers, say <code>x</code>, we have to scan the entire array to find the next number <code>y</code> which is <code>value - x</code> where value is the input parameter. Can we change our array somehow so that this search becomes faster?\",\"The second train of thought is, without changing the array, can we use additional space somehow? Like maybe a hash map to speed up the search?\"],\"similarQuestions\":\"[{\\"title\\": \\"3Sum\\", \\"titleSlug\\": \\"3sum\\", \\"difficulty\\": \\"Medium\\", \\"translatedTitle\\": \\"\\u4e09\\u6570\\u4e4b\\u548c\\", \\"isPaidOnly\\": false}, {\\"title\\": \\"4Sum\\", \\"titleSlug\\": \\"4sum\\", \\"difficulty\\": \\"Medium\\", \\"translatedTitle\\": \\"\\u56db\\u6570\\u4e4b\\u548c\\", \\"isPaidOnly\\": false}, {\\"title\\": \\"Two Sum II - Input Array Is Sorted\\", \\"titleSlug\\": \\"two-sum-ii-input-array-is-sorted\\", \\"difficulty\\": \\"Medium\\", \\"translatedTitle\\": \\"\\u4e24\\u6570\\u4e4b\\u548c II - \\u8f93\\u5165\\u6709\\u5e8f\\u6570\\u7ec4\\", \\"isPaidOnly\\": false}, {\\"title\\": \\"Two Sum III - Data structure design\\", \\"titleSlug\\": \\"two-sum-iii-data-structure-design\\", \\"difficulty\\": \\"Easy\\", \\"translatedTitle\\": \\"\\u4e24\\u6570\\u4e4b\\u548c III - \\u6570\\u636e\\u7ed3\\u6784\\u8bbe\\u8ba1\\", \\"isPaidOnly\\": true}, {\\"title\\": \\"Subarray Sum Equals K\\", \\"titleSlug\\": \\"subarray-sum-equals-k\\", \\"difficulty\\": \\"Medium\\", \\"translatedTitle\\": \\"\\u548c\\u4e3a K \\u7684\\u5b50\\u6570\\u7ec4\\", \\"isPaidOnly\\": false}, {\\"title\\": \\"Two Sum IV - Input is a BST\\", \\"titleSlug\\": \\"two-sum-iv-input-is-a-bst\\", \\"difficulty\\": \\"Easy\\", \\"translatedTitle\\": \\"\\u4e24\\u6570\\u4e4b\\u548c IV - \\u8f93\\u5165\\u4e8c\\u53c9\\u641c\\u7d22\\u6811\\", \\"isPaidOnly\\": false}, {\\"title\\": \\"Two Sum Less Than K\\", \\"titleSlug\\": \\"two-sum-less-than-k\\", \\"difficulty\\": \\"Easy\\", \\"translatedTitle\\": \\"\\u5c0f\\u4e8e K \\u7684\\u4e24\\u6570\\u4e4b\\u548c\\", \\"isPaidOnly\\": true}]\",\"sampleTestCase\":\"[2,7,11,15]\n9\",\"exampleTestcases\":\"[2,7,11,15]\n9\n[3,2,4]\n6\n[3,3]\n6\",\"exampleTestcaseList\":[\"[2,7,11,15]\n9\",\"[3,2,4]\n6\",\"[3,3]\n6\"],\"jsonExampleTestcases\":\"[\\"[2,7,11,15]\\n9\\", \\"[3,2,4]\\n6\\", \\"[3,3]\\n6\\"]\",\"metaData\":\"{\n  \\"name\\": \\"twoSum\\",\n  \\"params\\": [\n    {\n      \\"name\\": \\"nums\\",\n      \\"type\\": \\"integer[]\\"\n    },\n    {\n      \\"name\\": \\"target\\",\n      \\"type\\": \\"integer\\"\n    }\n  ],\n  \\"return\\": {\n    \\"type\\": \\"integer[]\\",\n    \\"size\\": 2\n  },\n  \\"manual\\": false\n}\",\"codeSnippets\":[{\"lang\":\"C++\",\"langSlug\":\"cpp\",\"code\":\"class Solution {\npublic:\n    vector<int> twoSum(vector<int>& nums, int target) {\n        \n    }\n};\"},{\"lang\":\"Java\",\"langSlug\":\"java\",\"code\":\"class Solution {\n    public int[] twoSum(int[] nums, int target) {\n\n    }\n}\"},{\"lang\":\"Python\",\"langSlug\":\"python\",\"code\":\"class Solution(object):\n    def twoSum(self, nums, target):\n        \\"\\"\\"\n        :type nums: List[int]\n        :type target: int\n        :rtype: List[int]\n        \\"\\"\\"\"},{\"lang\":\"Python3\",\"langSlug\":\"python3\",\"code\":\"class Solution:\n    def twoSum(self, nums: List[int], target: int) -> List[int]:\"},{\"lang\":\"C\",\"langSlug\":\"c\",\"code\":\"/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* twoSum(int* nums, int numsSize, int target, int* returnSize){\n\n}\"},{\"lang\":\"C#\",\"langSlug\":\"csharp\",\"code\":\"public class Solution {\n    public int[] TwoSum(int[] nums, int target) {\n\n    }\n}\"},{\"lang\":\"JavaScript\",\"langSlug\":\"javascript\",\"code\":\"/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[]}\n */\nvar twoSum = function(nums, target) {\n\n};\"},{\"lang\":\"Ruby\",\"langSlug\":\"ruby\",\"code\":\"# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer[]}\ndef two_sum(nums, target)\n\nend\"},{\"lang\":\"Swift\",\"langSlug\":\"swift\",\"code\":\"class Solution {\n    func twoSum(_ nums: [Int], _ target: Int) -> [Int] {\n\n    }\n}\"},{\"lang\":\"Go\",\"langSlug\":\"golang\",\"code\":\"func twoSum(nums []int, target int) []int {\n\n}\"},{\"lang\":\"Scala\",\"langSlug\":\"scala\",\"code\":\"object Solution {\n    def twoSum(nums: Array[Int], target: Int): Array[Int] = {\n\n    }\n}\"},{\"lang\":\"Kotlin\",\"langSlug\":\"kotlin\",\"code\":\"class Solution {\n    fun twoSum(nums: IntArray, target: Int): IntArray {\n\n    }\n}\"},{\"lang\":\"Rust\",\"langSlug\":\"rust\",\"code\":\"impl Solution {\n    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {\n\n    }\n}\"},{\"lang\":\"PHP\",\"langSlug\":\"php\",\"code\":\"class Solution {\n\n    /**\n     * @param Integer[] $nums\n     * @param Integer $target\n     * @return Integer[]\n     */\n    function twoSum($nums, $target) {\n\n    }\n}\"},{\"lang\":\"TypeScript\",\"langSlug\":\"typescript\",\"code\":\"function twoSum(nums: number[], target: number): number[] {\n\n};\"},{\"lang\":\"Racket\",\"langSlug\":\"racket\",\"code\":\"(define/contract (two-sum nums target)\n  (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n  )\"},{\"lang\":\"Erlang\",\"langSlug\":\"erlang\",\"code\":\"-spec two_sum(Nums :: [integer()], Target :: integer()) -> [integer()].\ntwo_sum(Nums, Target) ->\n  .\"},{\"lang\":\"Elixir\",\"langSlug\":\"elixir\",\"code\":\"defmodule Solution do\n  @spec two_sum(nums :: [integer], target :: integer) :: [integer]\n  def two_sum(nums, target) do\n\n  end\nend\"},{\"lang\":\"Dart\",\"langSlug\":\"dart\",\"code\":\"class Solution {\n  List<int> twoSum(List<int> nums, int target) {\n\n  }\n}\"}],\"topicTags\":[{\"name\":\"Array\",\"slug\":\"array\",\"translatedName\":\"\u6570\u7ec4\"},{\"name\":\"Hash Table\",\"slug\":\"hash-table\",\"translatedName\":\"\u54c8\u5e0c\u8868\"}],\"editorType\":\"CKEDITOR\"}}}"
⣾ Running test...2023/06/09 10:02:32 DEBU reading cookies browser=safari file=/Users/ding/Library/Cookies/Cookies.binarycookies
2023/06/09 10:02:32 DEBU failed to read cookies error="open /Users/ding/Library/Cookies/Cookies.binarycookies: operation not permitted"
2023/06/09 10:02:32 DEBU reading cookies browser=firefox file="/Users/ding/Library/Application Support/Firefox/Profiles/6idtsv2e.default-1686208684195/cookies.sqlite"
2023/06/09 10:02:32 DEBU no cookie found browser=firefox
2023/06/09 10:02:32 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies"
2023/06/09 10:02:32 DEBU failed to read cookies error="open /Users/ding/Library/Application Support/Google/Chrome/Default/Network/Cookies: no such file or directory"
2023/06/09 10:02:32 DEBU reading cookies browser=chrome file="/Users/ding/Library/Application Support/Google/Chrome/Default/Cookies"
2023/06/09 10:02:32 DEBU no cookie found browser=chrome
2023/06/09 10:02:32 DEBU finished reading cookies elapsed=1.89812ms
2023/06/09 10:02:32 ERRO failed to run test remotely question=two-sum err="failed to run test: no cookies found in browsers"

@j178
Copy link
Owner

j178 commented Jun 9, 2023

Thank you!

Something I want to confirm:

  1. Which version of Chrome you are using?
  2. Can you open the leetcode.cn page on Chrome, login in, open the DevTools (⌥ ⌘ I on macOS), and confirm that there are cookies named LEETCODE_SESSION and csrftoken?
image

@zrcoder
Copy link
Author

zrcoder commented Jun 9, 2023

Thank you!

Something I want to confirm:

  1. Which version of Chrome you are using?
  2. Can you open the leetcode.cn page on Chrome, login in, open the DevTools (⌥ ⌘ I on macOS), and confirm that there are cookies named LEETCODE_SESSION and csrftoken?
  1. chrome: Version 114.0.5735.106 (Official Build) (x86_64)
  2. yes, there are cookies named LEETCODE_SESSION and csrftoken in dev tools.

@j178
Copy link
Owner

j178 commented Jun 12, 2023

I have no idea why it doesn't work. I can't reproduce the problem on my computer, so I can't help solve it. Sorry. If you are able to debug it yourself, I'm happy to provide help.

@j178 j178 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2023
@j178 j178 reopened this Aug 4, 2023
@j178
Copy link
Owner

j178 commented Aug 4, 2023

I reproduced this issue today, and it seems that the root cause is the cookie file is being used by the chrome process.

 leetcode  leetgo whoami
2023/08/04 19:37:47 DEBU reading cookies browser=chrome file="C:\Users\nigel\AppData\Local\Google\Chrome\User Data\Default\Network\Cookies"
2023/08/04 19:37:47 DEBU failed to read cookies error="open C:\Users\nigel\AppData\Local\Google\Chrome\User Data\Default\Network\Cookies: The process cannot access the file because it is being used by another process."
2023/08/04 19:37:47 DEBU reading cookies browser=chrome file="C:\Users\nigel\AppData\Local\Google\Chrome\User Data\Default\Cookies"
2023/08/04 19:37:47 DEBU failed to read cookies error="open C:\Users\nigel\AppData\Local\Google\Chrome\User Data\Default\Cookies: The system cannot find the file specified."
2023/08/04 19:37:47 DEBU reading cookies browser=chrome file="C:\Users\nigel\AppData\Local\Google\Chrome\User Data\Profile 1\Network\Cookies"
2023/08/04 19:37:47 DEBU no cookie found browser=chrome
2023/08/04 19:37:47 DEBU reading cookies browser=chrome file="C:\Users\nigel\AppData\Local\Google\Chrome\User Data\Profile 1\Cookies"
2023/08/04 19:37:47 DEBU failed to read cookies error="open C:\Users\nigel\AppData\Local\Google\Chrome\User Data\Profile 1\Cookies: The system cannot find the file specified."
2023/08/04 19:37:47 DEBU finished reading cookies elapsed=1.5764ms
2023/08/04 19:37:47 FATA no cookies found in browsers

@charleszhangjie
Copy link

charleszhangjie commented Oct 22, 2023

I tried some browsers and it says "The process cannot access the file because it is being used by another process."
when I closed the browser (including backgroud process in task manager),the leetgo read cookies successfully.
so "another process" means the browser process itself !
I wonder is it a bug that it only works when there is no browser process is running.

@j178 j178 added the windows Windows specific issue label Oct 22, 2023
@j178
Copy link
Owner

j178 commented Oct 22, 2023

The root cause is that Chrome open its Cookie file in the exclusive mode (set dwShareMode to 0 in CreateFileW), so Windows prevents any process to access the file again.

This problem is specific to Windows and cannot be addressed directly by leetgo.

But I have a workaround. I log into LeetCode using an alertnate browser such as Edge, but I mainly use Chrome, so when I use leetgo, it can read cookies from Edge since it is not running.

@charleszhangjie
Copy link

The root cause is that Chrome open its Cookie file in the exclusive mode (set dwShareMode to 0 in CreateFileW), so Windows prevents any process to access the file again.

This problem is specific to Windows and cannot be addressed directly by leetgo.

But I have a workaround. I log into LeetCode using an alertnate browser such as Edge, but I mainly use Chrome, so when I use leetgo, it can read cookies from Edge since it is not running.

Is there any way to set something to change the cookie file share mode on Windows? This problem seems to have emerged only in the recent months

@j178
Copy link
Owner

j178 commented Oct 22, 2023

Is there any way to set something to change the cookie file share mode on Windows?

As far as I know, there is not.

This problem seems to have emerged only in the recent months

Yes, it worked fine, perhaps Chrome/Chromium changed the Cookies file mode recently.

@j178 j178 added the help wanted Extra attention is needed label Nov 12, 2023
@JesseGuerrero
Copy link

JesseGuerrero commented Jan 7, 2024

I am also having trouble using the browser. I am using WSL2 Ubuntu on Windows 10 with Chrome. I had to use cookies and set them in bashrc. Works great that way. I don't know how long leetcode sessions last though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed windows Windows specific issue
Projects
None yet
Development

No branches or pull requests

4 participants