Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rhyryy opened this issue Aug 26, 2023 · 6 comments
Closed

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

rhyryy opened this issue Aug 26, 2023 · 6 comments
Labels

Comments

@rhyryy
Copy link

rhyryy commented Aug 26, 2023

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

@MinatoAquaDaiSuki
Copy link

MinatoAquaDaiSuki commented Sep 10, 2023

现在手动指定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
Copy link
Owner

upbit commented Sep 10, 2023

现在手动指定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是否能访问

@upbit upbit added the question label Sep 10, 2023
@rhyryy
Copy link
Author

rhyryy commented Sep 11, 2023

现在手动指定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"))

@MinatoAquaDaiSuki
Copy link

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

@upbit
Copy link
Owner

upbit commented Sep 17, 2023

现在手动指定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上

@upbit upbit added bug and removed question labels Sep 17, 2023
@upbit upbit closed this as completed Mar 3, 2024
@upbit
Copy link
Owner

upbit commented Mar 3, 2024

fixed in 50b9cb8

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

No branches or pull requests

3 participants