Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

IPv6回环地址请求导致406 “操作频繁,请稍候再试” #1863

Open
bczhc opened this issue Dec 28, 2023 · 1 comment
Open

IPv6回环地址请求导致406 “操作频繁,请稍候再试” #1863

bczhc opened this issue Dec 28, 2023 · 1 comment

Comments

@bczhc
Copy link

bczhc commented Dec 28, 2023

环境

  • 系统/平台: Archlinux rolling; kernel 6.7.0-rc7-modified-g861deac3b092-dirty

  • nodejs 版本: v21.4.0

  • API版本: 4.14.0

出现问题

当使用IPv6的回环地址请求时,返回406:

{"msg":"操作频繁,请稍候再试","code":406,"message":"操作频繁,请稍候再试"}

重现步骤

请求代码

#!/bin/env ruby

require 'net/http'
require 'json'

def fetch(url)
  uri = URI(url)
  puts "Fetching #{url}"
  response = Net::HTTP.get_response uri
  fail "Non-200 status code: #{response.code}; body: #{response.body}" unless response.code == '200'
  response.body
end

id=2666362456
while true
  sleep 1
  url="http://[::1]:3000/playlist/detail?id=#{id}"
  body = fetch url
  puts body[0..100]
  id += 1
end

// implementation("io.ktor:ktor-client-cio-jvm:2.2.2")
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlin.system.exitProcess

fun main() {
    runBlocking { suspendMain() }
}

suspend fun suspendMain() {
    val client = HttpClient()
    var id = 2666362456
    while (true) {
        delay(1000)
        val url = "http://[::1]:3000/playlist/detail?id=$id"
        val response = client.get(url)
        if (response.status.value != 200) {
            println("Error ${response.status.value} ${response.status.description} ${response.bodyAsText()}")
            exitProcess(1)
        }
        println(response.bodyAsText().substring(0 until 100))
        ++id
    }
}
  1. 启动NeteaseCloudMusicApi
  2. 运行上面的任何一个代码
  3. 应该会很快输出错误(我这边第一条请求就直接406)
    ~/code/ruby ❯ /home/bczhc/code/ruby/demo2                                                                                                                                                    ✘ INT 5s 22:42:28
    Fetching http://[::1]:3000/playlist/detail?id=2666362456
    /home/bczhc/code/ruby/demo2:10:in `fetch': Non-200 status code: 406; body: {"msg":"操作频繁,请稍候再试","code":406,"message":"操作频繁,请稍候再试"} (RuntimeError)
            from /home/bczhc/code/ruby/demo2:18:in `<main>'

期待效果

正常请求

# `[::1]`改成`127.0.0.1`之后

~/code/ruby ❯ /home/bczhc/code/ruby/demo2 
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362457
{"code":200,"relatedVideos":{},"playlist":{"id":2666362457,"name":"我喜欢的音乐","coverImgId":3
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362458
{"code":200,"relatedVideos":{},"playlist":{"id":2666362458,"name":"橙光","coverImgId":7146825581822
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362459
{"code":200,"relatedVideos":{},"playlist":{"id":2666362459,"name":"我喜欢的音乐","coverImgId":1
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362460
{"code":200,"relatedVideos":{},"playlist":{"id":2666362460,"name":"nc","coverImgId":10995116547412140
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362461
{"code":200,"relatedVideos":{},"playlist":{"id":2666362461,"name":"日文","coverImgId":1099511638520
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362462
{"code":200,"relatedVideos":{},"playlist":{"id":2666362462,"name":"我喜欢的音乐","coverImgId":3
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362463
{"code":200,"relatedVideos":{},"playlist":{"id":2666362463,"name":"填煙花美但只是瞬間玻喜�
Fetching http://127.0.0.1:3000/playlist/detail?id=2666362464
{"code":200,"relatedVideos":{},"playlist":{"id":2666362464,"name":"我喜欢的音乐","coverImgId":3

更多注明

当把url中的[::1]改成127.0.0.1后,就不报操作频繁的错了,而以IPv6回环地址请求时就会,正常的话不应该出现这样的差别。

最开始这个问题,是我用的http://localhost:3000地址,然后发现用Ruby请求就老报这个错,很奇怪。我并没频繁请求,已经等了很久了再请求还是那样。后来又发现在浏览器里和IntelliJ的HTTP Client里请求都是正常的,唯独Ruby出错。我又在Kotlin实现了同样的逻辑,Kotlin也是好的。在Wireshark中比较Ruby和Kotlin的请求,发现Ruby对localhost使用IPv6回环地址,而Kotlin的ktor还是IPV4,遂发现这个问题。

@bczhc bczhc changed the title IPv6导致406 “操作频繁,请稍候再试” IPv6回环地址请求导致406 “操作频繁,请稍候再试” Dec 28, 2023
@Binaryify
Copy link
Owner

这个我也不清楚了,先用着 ipv4 吧

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants