skygragon / leetcode-cli

A cli tool to enjoy leetcode!
MIT License
3.64k stars 457 forks source link

"leetcode show" no longer display question descriptions and "submit" returns "http error [500]" #41

Closed BkunS closed 7 years ago

BkunS commented 7 years ago

Updated to 0.10.0 and logged in, but "leetcode show" command can no longer display the description of the problem. When I try to submit the solution generated by "leetcode show [Number] -g -x -l java", it always returns "[ERROR] http error [500]", but "leetcode test" command works just fine.

skygragon commented 7 years ago

"http error [500]" means leetcode.com response a 500 HTTP error, you can run leetcode show command again with "-vv" to enable trace log to see what happens in the HTTP traffic.

e.g.

leetcode show 1 -gxl java -vv
BkunS commented 7 years ago

I guess it might be due to the api change on leetcode side that the "show" command no longer gives the problem descriptions. Would you mind checking it? Cuz without the descriptions, the leetcode-cli is almost useless. And here's what I got for running the code:

$ leetcode submit 576.out-of-boundary-paths.java -vv [TRACE] REQUEST %s { url: 'https://leetcode.com/api/problems/algorithms/', headers: { Cookie: 'LEETCODE_SESSION=;csrftoken=;', 'X-CSRFToken': '', 'X-Requested-With': 'XMLHttpRequest' }, expectedStatus: 200, retry: 0, callback: [Function] } [TRACE] REQUEST %s make request https://leetcode.com/api/problems/algorithms/ [TRACE] REQUEST %s onRequestResponse https://leetcode.com/api/problems/algorithms/ 200 { server: 'nginx', date: 'Fri, 09 Jun 2017 03:27:53 GMT', 'content-type': 'text/html; charset=utf-8', 'transfer-encoding': 'chunked', connection: 'close', vary: 'Accept-Encoding, Accept, Cookie', 'x-frame-options': 'SAMEORIGIN', allow: 'GET, HEAD, OPTIONS' } [TRACE] REQUEST %s reading response's body [TRACE] REQUEST %s finish init function https://leetcode.com/api/problems/algorithms/ [TRACE] REQUEST %s response end https://leetcode.com/api/problems/algorithms/ 200 { server: 'nginx', date: 'Fri, 09 Jun 2017 03:27:53 GMT', 'content-type': 'text/html; charset=utf-8', 'transfer-encoding': 'chunked', connection: 'close', vary: 'Accept-Encoding, Accept, Cookie', 'x-frame-options': 'SAMEORIGIN', allow: 'GET, HEAD, OPTIONS' } [TRACE] REQUEST %s end event https://leetcode.com/api/problems/algorithms/ [TRACE] REQUEST %s has body https://leetcode.com/api/problems/algorithms/ 240505 [TRACE] REQUEST %s emitting complete https://leetcode.com/api/problems/algorithms/ [TRACE] REQUEST %s { url: 'https://leetcode.com/problems/out-of-boundary-paths/submit/', headers: { Cookie: ;', 'X-CSRFToken': '', 'X-Requested-With': 'XMLHttpRequest', Origin: 'https://leetcode.com', Referer: 'https://leetcode.com/problems/out-of-boundary-paths' }, expectedStatus: 200, retry: 0, body: { judge_type: 'large', lang: 'java', question_id: 576, test_mode: false, typed_code: '/\r\n [576] Out of Boundary Paths\r\n \r\n https://leetcode.com/problems/out-of-boundary-paths\r\n \r\n Hard (33.35%)\r\n Total Accepted: \r\n Total Submissions: \r\n Testcase Example: \'2\n2\n2\n0\n0\'\r\n \r\n Can you solve this problem? 🤔\r\n /\r\npublic class Solution {\r\n public int findPaths(int m, int n, int N, int i, int j) {\r\n\t\treturn 0;\r\n }\r\n}\r\n' }, method: 'POST', json: true, _delay: 1, callback: [Function] } [TRACE] REQUEST %s make request https://leetcode.com/problems/out-of-boundary-paths/submit/ [TRACE] REQUEST %s onRequestResponse https://leetcode.com/problems/out-of-boundary-paths/submit/ 500 { server: 'nginx', date: 'Fri, 09 Jun 2017 03:27:55 GMT', 'content-type': 'text/html; charset=utf-8', 'transfer-encoding': 'chunked', connection: 'close', vary: 'Cookie', 'x-frame-options': 'SAMEORIGIN' } [TRACE] REQUEST %s reading response's body [TRACE] REQUEST %s finish init function https://leetcode.com/problems/out-of-boundary-paths/submit/ [TRACE] REQUEST %s response end https://leetcode.com/problems/out-of-boundary-paths/submit/ 500 { server: 'nginx', date: 'Fri, 09 Jun 2017 03:27:55 GMT', 'content-type': 'text/html; charset=utf-8', 'transfer-encoding': 'chunked', connection: 'close', vary: 'Cookie', 'x-frame-options': 'SAMEORIGIN' } [TRACE] REQUEST %s end event https://leetcode.com/problems/out-of-boundary-paths/submit/ [TRACE] REQUEST %s has body https://leetcode.com/problems/out-of-boundary-paths/submit/ 27 [TRACE] REQUEST %s invalid JSON received https://leetcode.com/problems/out-of-boundary-paths/submit/ [TRACE] REQUEST %s emitting complete https://leetcode.com/problems/out-of-boundary-paths/submit/

skygragon commented 7 years ago

Seems there are at least 2 issues:

  1. the description is missing because leetcode.com doesn't provide info as before, we already have fixed for #39 , so you can update leetcode-cli again to have the fix.
  2. the submit failed with 500 error, I guess it might because there is a special unicode char "🤔" in the request that leetcode.com doesn't handle it well. I would dig this later, but you can try to delete that char in your java file to see if it works as I guessed.
BkunS commented 7 years ago

I know what was going on. Guess my terminal doesn't have the right font or encoding to display some symbols as you just pointed out, and it went in the java file as squares which causes the problem. By deleting those squares solves the problem. snipaste_20170609_000528 snipaste_20170609_000555

I think this issue is good to be closed.

skygragon commented 7 years ago

After you updated leetcode-cli, you can remove the cache (~/.lc/out-of-boundary-paths.json), and it will show the right description as expected:

$ leetcode show 576
[576] Out of Boundary Paths

https://leetcode.com/problems/out-of-boundary-paths

* Hard (33.34%)
* Total Accepted:    2279
* Total Submissions: 6836
* Testcase Example:  '2\n2\n2\n0\n0'

There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directions (up, down, left, right). However, you can at most move N times. Find out the number of paths to move the ball out of grid boundary. The answer may be very large, return it after mod 109 + 7.

Example 1:

Input:m = 2, n = 2, N = 2, i = 0, j = 0
Output: 6
Explanation:

Example 2:

Input:m = 1, n = 3, N = 3, i = 0, j = 1
Output: 12
Explanation:

Note:

Once you move the ball out of boundary, you cannot move it back.
The length and height of the grid is in range [1,50].
N is in range [0,50].
BkunS commented 7 years ago

Has new version updated on npm yet? It seems it is still 0.10.0 and nothing changed.

skygragon commented 7 years ago

not published to npm yet, while you can install from github directly

$ npm install -g skygragon/leetcode-cli

More info: https://skygragon.github.io/leetcode-cli/install

BkunS commented 7 years ago

I have permission issues of npm installing from private repo though there are some ways to work around, but no real solutions. I guess I'll just stick with official npm version and try installing it later when it's updated. Thanks a lot!

skygragon commented 7 years ago

Are you saying the npm permission issue when trying to install it globally?

BkunS commented 7 years ago

I have no issues installing it globally with sudo command, but have issues installing it from private GitHub repo. I saw the version on npm has bumped to 0.10.1, and after updating to it seems everything works again. Thanks!

Pyboon commented 6 years ago

[ERROR] Error: connect ECONNREFUSED 104.27.161.90:443 [0] why I had the issue in ubuntu 16.04 OS ?

skygragon commented 6 years ago

@Pyboon most time this connection refused error is due to a bad networking, it's too complex since every hop (e.g. routers, firewalls) might be the reason...