bilibili-API-collect
bilibili-API-collect copied to clipboard
Cookies 刷新意外 correspondPath 过期或错误
见 https://github.com/Nemo2011/bilibili-api/issues/687
之前一直都可以的,现在出问题了
有谁遇到过的吗?
示例
pip install bilibili-api-python
from bilibili_api import Credential, sync
sync(Credential(sessdata="", bili_jct="", ac_time_value="").refresh())
~~这太大坨了,我实在抠不出来~~
没有, 这边依然正常刷新, 试试检查你的本地时间是否正确 示例:
import re
import time
import requests
from Crypto.Cipher import PKCS1_OAEP
from Crypto.PublicKey.RSA import RsaKey
from Crypto.Hash import SHA256
public_key = RsaKey(
n=int('cb81dd8e02470656da04dd38544446e2a3412051cfe9adc6a330a5ef90228509684960970b91c3360ca29c49e1690ff8fa068cb9dfc6179d1e9585cb9424e847db1ef59f33e37dd4dca8ccfb7631ee9b4a92640d00c8204300152a0ab7cd802889d3445aec69918fe6022b534912e7b095be3424dad1ba81145e969b533181f1', 16),
e=65537
)
def getCorrespondUrl(timestamp:int):
data = f"refresh_{timestamp}".encode()
encrypted = PKCS1_OAEP.new(public_key, hashAlgo=SHA256).encrypt(data)
return f"https://www.bilibili.com/correspond/1/{encrypted.hex()}"
url = getCorrespondUrl(int(time.time() * 1000))
response = requests.get(url, headers={'user-agent': 'Mozilla/5.0'}, cookies={'SESSDATA': sess})
response.raise_for_status()
refresh_csrf = re.search(r'<div id="1-name">([0-9a-f]+)</div>', response.text).group(1)
print(refresh_csrf, len(refresh_csrf))
# *** 32
我现在也复现不出了...暂时搁置,看看我那边发 issue 的怎么说
如果你生成的 correnspondPath 里的 refresh_${timestampe} 里时间戳刚刚好是现在的,生成完就发...
有可能会发生你的时间比服务器时间早的情况,可以考虑把生成的时间戳提前一分钟
如果这节省了你一天(或者其他值)的时间,请加个 reaction 告诉其他人这个方法有效....
问题解决了, 这的issues忘关了?