You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env python# -*- coding: utf-8 -*-importasyncio# import uuid# import sentry_sdkfrompixivpy_asyncimportAppPixivAPI# _USERNAME = "userbay"# _PASSWORD = "UserPay"_TOKEN="uXooTT7xz9v4mflnZqJUO7po9W5ciouhKrIDnI2Dv3c"# sentry_sdk.init(# dsn="https://[email protected]/111",# traces_sample_rate=1.0# )asyncdef_main(aapi):
""" Tips: How to create a proxy for Pixiv api? Just throw the following code into a CloudFlare worker. ```js addEventListener("fetch", e => { let t = e.request, d = new URL(t.url); d.hostname = "app-api.pixiv.net"; // Or public-api.secure.pixiv.net, oauth.secure.pixiv.net e.respondWith(fetch(d, {body: t.body, headers: t.headers, method: t.method})) }); ``` """# aapi.set_api_proxy(app_hosts="", auth_hosts="", pub_hosts="")# await aapi.login(_USERNAME, _PASSWORD)awaitaapi.login(refresh_token=_TOKEN)
# result = await aapi.illust_ranking('day')result=awaitaapi.user_bookmarks_illust(
12345678, restrict="private", req_auth=True
)
foriteminresult.illusts:
print(item.image_urls['large'])
# await aapi.download(item.image_urls['large'])defmain():
loop=asyncio.get_event_loop()
loop.run_until_complete(_main(AppPixivAPI(bypass=True)))
if__name__=='__main__':
main()
命令行原始报错
Task exception was never retrieved
future: <Task finished name='Task-5' coro=<ByPassResolver._resolve() done, defined at /home/pwuser/.local/lib/python3.8/site-packages/pixivpy_async/bypass_sni.py:88> exception=ClientConnectorError(ConnectionKey(host='2606:4700:4700::1001', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None), OSError(99, 'Cannot assign requested address'))>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
File "/usr/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
raise exceptions[0]
File "/usr/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
sock = await self._connect_sock(
File "/usr/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
return await fut
File "/usr/lib/python3.8/asyncio/selector_events.py", line 501, in _sock_connect
sock.connect(address)
OSError: [Errno 99] Cannot assign requested address
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pwuser/.local/lib/python3.8/site-packages/pixivpy_async/bypass_sni.py", line 98, in _resolve
async with session.get(endpoint, params=params, headers={"accept": "application/dns-json"}, timeout=ClientTimeout(total=timeout)) as resp:
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 1141, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 536, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 540, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 901, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 988, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 2606:4700:4700::1001:443 ssl:default [Cannot assign requested address]
Task exception was never retrieved
future: <Task finished name='Task-6' coro=<ByPassResolver._resolve() done, defined at /home/pwuser/.local/lib/python3.8/site-packages/pixivpy_async/bypass_sni.py:88> exception=ClientConnectorError(ConnectionKey(host='2606:4700:4700::1111', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None), OSError(99, 'Cannot assign requested address'))>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
File "/usr/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
raise exceptions[0]
File "/usr/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
sock = await self._connect_sock(
File "/usr/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
return await fut
File "/usr/lib/python3.8/asyncio/selector_events.py", line 501, in _sock_connect
sock.connect(address)
OSError: [Errno 99] Cannot assign requested address
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pwuser/.local/lib/python3.8/site-packages/pixivpy_async/bypass_sni.py", line 98, in _resolve
async with session.get(endpoint, params=params, headers={"accept": "application/dns-json"}, timeout=ClientTimeout(total=timeout)) as resp:
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 1141, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 536, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 540, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 901, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 988, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 2606:4700:4700::1111:443 ssl:default [Cannot assign requested address]
caught: TimeoutError()
caught: ClientConnectorError(ConnectionKey(host='2606:4700:4700::1111', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None), OSError(99, 'Cannot assign requested address'))
caught: ClientConnectorError(ConnectionKey(host='2606:4700:4700::1001', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None), OSError(99, 'Cannot assign requested address'))
https://i.pximg.net/c/600x1200_90_webp/img-master/img/2022/06/19/23/21/09/99169234_p0_master1200.jpg
https://i.pximg.net/c/600x1200_90_webp/img-master/img/2022/06/12/22/46/48/99012724_p0_master1200.jpg
https://i.pximg.net/c/600x1200_90_webp/img-master/img/2022/07/10/20/37/14/99635521_p0_master1200.jpg
...
使用
AppPixivAPI(bypass=True)
在 DNS over HTTP(s) 解析 Pixiv IP 的时候尝试请求 IPv6 dns-query 接口,在 IPv6 支持不完全的服务器上会引起OSError: [Errno 101] Network is unreachable
,虽然不影响使用,但是报错信息较长,有点反感,是否可以将 IPv6 地址的 dns-query 接口与 IPv4 的区分开?pixivpy-async/pixivpy_async/bypass_sni.py
Lines 14 to 24 in ef877db
下面是我参考仓库里的文件
/demo/demo_api_proxy.py
修改的代码以及一些报错信息。环境为 Python 3.8.10 & PixivPy-Async 1.2.14,运行在 Docker 容器内(在主机上运行也存在类似报错)。代码
命令行原始报错
我用
ip addr
检查了一下主机网络,参考 IPv6 Network is unreachable (os error 101) - StackOverflow 的回答认为是由于服务器 IPv6 is enabled but dynamic assignment of IPv6 addresses is not enabled.The text was updated successfully, but these errors were encountered: