upbit/pixivpy

ByPassSniApi示例中api.auth方法报错

rhyryy opened this issue · 6 comments

rhyryy commented

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参数错误?

现在手动指定headers也不行了 有解决思路吗
报错信息:
pixivpy3.utils.PixivError: requests POST https://oauth.secure.pixiv.net/auth/token error: HTTPSConnectionPool(host='oauth.secure.pixiv.net', port=443): Max retries exceeded with url: /auth/token (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))))

upbit commented

现在手动指定headers也不行了 有解决思路吗 报错信息: pixivpy3.utils.PixivError: requests POST https://oauth.secure.pixiv.net/auth/token error: HTTPSConnectionPool(host='oauth.secure.pixiv.net', port=443): Max retries exceeded with url: /auth/token (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))))

应该是2个不同的问题。第一个指定Host可能是检查,解析的IP是正确的:

inetnum:        210.140.92.128 - 210.140.92.255
netname:        PIXIV-NET
descr:          pixiv technologies Inc.
country:        JP
admin-c:        JP00180902
tech-c:         JP00180902
remarks:        This information has been partially mirrored by APNIC from
remarks:        JPNIC. To obtain more specific information, please use the
remarks:        JPNIC WHOIS Gateway at
remarks:        http://www.nic.ad.jp/en/db/whois/en-gateway.html or
remarks:        whois.nic.ad.jp for WHOIS client. (The WHOIS client
remarks:        defaults to Japanese output, use the /e switch for English
remarks:        output)
last-modified:  2019-08-27T19:41:02Z
source:         JPNIC

而后面这个是因为解析到的地址无法访问,或者解析失败用了域名。你可以分步检查下是否拿到IP,以及IP是否能访问

rhyryy commented

现在手动指定headers也不行了 有解决思路吗 报错信息: pixivpy3.utils.PixivError: requests POST https://oauth.secure.pixiv.net/auth/token error: HTTPSConnectionPool(host='oauth.secure.pixiv.net', port=443): Max retries exceeded with url: /auth/token (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))))

#138(commit) 是否问题与此相同? 可尝试修改host或调用api.require_appapi_hosts(hostname="public-api.secure.pixiv.net"))

第二个好像是我自己开的代理被SSL拦截了 指定host之后是可以的

upbit commented

现在手动指定headers也不行了 有解决思路吗 报错信息: pixivpy3.utils.PixivError: requests POST https://oauth.secure.pixiv.net/auth/token error: HTTPSConnectionPool(host='oauth.secure.pixiv.net', port=443): Max retries exceeded with url: /auth/token (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))))

#138(commit) 是否问题与此相同? 可尝试修改host或调用api.require_appapi_hosts(hostname="public-api.secure.pixiv.net"))

试了下,确实这个方法可以绕过(代码如下)。推测是默认 app-api.pixiv.net 指向IP不支持SSL,换成 app-api.secure.pixiv.net 的域名解析IP就可以:

def main():
    api = ByPassSniApi()

    # 主要改动
    api.require_appapi_hosts(hostname="app-api.secure.pixiv.net")

    print(api.auth(refresh_token=_REFRESH_TOKEN))
    json_result = api.illust_ranking("day", date=(datetime.now() - timedelta(days=5)).strftime("%Y-%m-%d"))

下个版本我更新到BAPI的默认host上

fixed in 50b9cb8