Skip to content

ChannelSeries合集经常会出现报错,有时候可以抓出来有时候则不行(代码无改动的情况下),是否是和B站那边有关系? #624

Answered by TimG233
TimG233 asked this question in Q&A
Discussion options

You must be logged in to vote

哦?我似乎发现了问题所在,我们似乎需要给ChannelSeries初始化里api请求加一个ua的请求头

resp = json.loads(httpx.get(api["url"], params=params).text)["data"]

比如这样

headers={"User-Agent": "Mozilla/5.0"}
resp = json.loads(httpx.get(api["url"], headers=headers, params=params).text)['data']

加了之后,我跑了一下,发现不会再出现上述的非正常返回(被服务器拒绝)的情况。但我只跑了50次(无报错),我怕B站给我风控了哈哈哈。但比之前那种50%/50%的情况好多了。如果你可以测试一下证实的话最好了,如果需要我PR的话我也可以顺手弄了。

至于为什么不加ua他会一会儿好一会儿不好,我也不是很清楚,我不知道这是不是和B站服务器端的缓存有任何关系导致的,如果你知道这个就更好了!感谢

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@z0z0r4
Comment options

z0z0r4 Jan 4, 2024
Collaborator

@z0z0r4
Comment options

z0z0r4 Jan 4, 2024
Collaborator

Comment options

You must be logged in to vote
5 replies
@z0z0r4
Comment options

z0z0r4 Jan 4, 2024
Collaborator

@TimG233
Comment options

@z0z0r4
Comment options

z0z0r4 Jan 5, 2024
Collaborator

@TimG233
Comment options

@z0z0r4
Comment options

z0z0r4 Jan 5, 2024
Collaborator

Answer selected by z0z0r4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants