joshcai / leetcode-sync

GitHub Action for syncing LeetCode submissions to GitHub
287 stars 59 forks source link

Error: Error: Request failed with status code 401 #18

Open doubley318 opened 2 years ago

doubley318 commented 2 years ago

Sorry! After I follow your tutorial, I always get this error and I don't know how to deal with it. image sync_leetcode.yml

# This is a basic workflow to help you get started with Actions

name: Sync Leetcode

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  # cron: 'min hour day month week (year)'
  workflow_dispatch:
  schedule:
    - cron:  '5 * * * *'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      # - uses: actions/checkout@v3

      # Runs a single command using the runners shell
      # - name: Run a one-line script
      #   run: echo Hello, world!

      # # Runs a set of commands using the runners shell
      # - name: Run a multi-line script
      #   run: |
      #     echo Add other actions to build,
      #     echo test, and deploy your project.
      - name: Sync
        uses: joshcai/leetcode-sync@v1.4
        with:
          github-token: ${{ github.token }}
          leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }}
          leetcode-session: ${{ secrets.LEETCODE_SESSION }}
          destination-folder: my-folder
# 

image And these file's contents are: image I don't know what went wrong.

Thank you for your help!

joshcai commented 2 years ago

Hi @doubley318, I unfortunately don't see anything wrong from the screenshots you provided - one thing you could try is to run this Chrome extension instead: https://github.com/joshcai/leetcode-sync-chrome/releases/tag/v0.0.1

It should set up all the variables for you in case there were any issues with copying the values over.

vishrutkmr7 commented 2 years ago

Even I was facing this issue. It got fixed when I updated my secret with the latest values... Probably the cookie values expired.

wmorgue commented 1 year ago

Two weeks later I encountered the same error. It looks like the token or session expires after 2 weeks.

mue8010 commented 1 year ago

Do you think it's possible to fetch the token systematically from Leetcode?

zhangjie119 commented 1 year ago

This seems to be a unique problem of Chinese leetcode. I encountered the same error for https://leetcode.cn/, but https://leetcode.com/, it works.

jaspinderkohli commented 1 year ago

Two weeks later I encountered the same error. It looks like the token or session expires after 2 weeks.

Same here, looks like LeeetCode session has an expiry of two weeks. Once I update the value of LeetCode session in "Actions secrets and variables" it works fine. (Using https://leetcode.com)


Added the issue here with details - #39

now-youre-gittin-it commented 1 year ago

I faced this within a span of a few hours of running the action successfully today even though I had set the LEETCODE_SESSION and CSRF_TOKEN values just yesterday. Updating these two values resolved the issue, even though the time span was certainly not two weeks!

chantellecv commented 11 months ago

I faced this within a span of a few hours of running the action successfully today even though I had set the LEETCODE_SESSION and CSRF_TOKEN values just yesterday. Updating these two values resolved the issue, even though the time span was certainly not two weeks!

I believe what happened was that the values already had a set date to expire when you obtained them. So you probably obtained them just a day before the expiry date. The validity of the values should certainly last more than a few days. Hope this helps!

Wayne0758 commented 1 month ago

Helpful!