Skip to content

ByPassSniApi示例中api.auth方法报错 #279

@rhyryy

Description

@rhyryy

pixivpy3版本:3.7.2
报错信息:
pixivpy3.utils.PixivError: requests POST https://210.140.92.183/auth/token error: HTTPSConnectionPool(host='210.140.92.183', port=443): Max retries exceeded with url: /auth/token (Caused by SSLError(CertificateError("hostname '210.140.92.183' doesn't match either of '.pixiv.net', 'pixiv.me', 'public-api.secure.pixiv.net', 'oauth.secure.pixiv.net', 'www.pixivision.net', 'fanbox.cc', '.fanbox.cc', 'pixiv.net'")))

报错代码如下

import sys

from pixivpy3 import *

sys.dont_write_bytecode = True
_REFRESH_TOKEN = "xxxxxxxxxxx"
if __name__ == '__main__':
    api = ByPassSniApi() 
    print(api.require_appapi_hosts(hostname="public-api.secure.pixiv.net")) # 输出为https://210.140.92.183
    api.set_accept_language("en-us")
    print(api.auth(refresh_token=_REFRESH_TOKEN))
    json_result = api.illust_detail(59580629)
    print(json_result)

当手动指定请求头host后,工作正常

import sys

from pixivpy3 import *

sys.dont_write_bytecode = True
_REFRESH_TOKEN = "xxxxxxxxxxx"
if __name__ == '__main__':
    api = ByPassSniApi() 
    print(api.require_appapi_hosts(hostname="public-api.secure.pixiv.net"))# 输出为https://210.140.92.183
    api.set_accept_language("en-us")
    headers = {"host": "oauth.secure.pixiv.net"} # 手动指定请求头host
    print(api.auth(refresh_token=_REFRESH_TOKEN, headers=headers))
    json_result = api.illust_detail(59580629)
    print(json_result)

auth函数中与该逻辑有关的代码似乎如下

headers_ = CaseInsensitiveDict(headers or {})
......
# noinspection PyUnresolvedReferences
if not hasattr(self, "hosts") or self.hosts == "https://app-api.pixiv.net":
    auth_hosts = "https://oauth.secure.pixiv.net"
else:
    # noinspection PyUnresolvedReferences
    auth_hosts = self.hosts  # BAPI解析成IP的场景
    headers_["host"] = "oauth.secure.pixiv.net"
......
r = self.requests_call("POST", url, headers=headers, data=data) #在此处使用的为传入的headers参数 

是否在requests_call中传入的headers参数错误?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions