txperl / PixivBiu

Pixiv 辅助工具
https://biu.tls.moe/
MIT License
989 stars 70 forks source link

几个疑问:代理、端口与热门搜索 #6

Closed Azureki closed 3 years ago

Azureki commented 3 years ago
  1. 代理:配置文件 config.yml 中举的例子是 http 代理,我一般用 socks5 代理,可是启动之后加载不了图片。是只支持 http 代理吗?发现代理失效之后我填了 "no",但是重启依然没有图。
  2. 端口:在命令行打开,Ctrl + C 关闭,再次打开时提示端口被占用。但是无论是 lsof 还是 netstat 都看不到 4001 被占用,在配置文件中修改端口之后再启动,依然提示端口被占用。
  3. 搜索:我看到 readme 中提到使用了 pixivpy 的 api,但代码中似乎只在 core 部分用了他的 api 来登录,而搜索部分没有使用。而且因为一般的按热度排序也只能看到前30条,所以 pixivpy 其实没有提供热度搜索的api(如果是非会员的话)。参考: https://github.com/upbit/pixivpy/pull/134 。请问 PixivBiu 是如何实现的?
txperl commented 3 years ago

#A1 你指的启动后加载不了图片,应该是网页上的预览图吧?这个与配置项里的代理地址无关。因为用的是第三方反代服务器,加载不出来多半是网络环境问题,可以尝试在浏览的时候开启全局模式。

不过直接在配置项的代理中填入 socks5 地址也是不可行的。Python 貌似没有官方封装 socks 协议,需要安装一下 pip install PySocks 才可正常使用。后续版本会在 requirements.txt 中加入此项的。

#A2 抱歉,这个我暂时没什么头绪,我也没有遇到过...

有条件的话可以手动测试一下这段代码(isPortInUse),如果能附上报错那就可以排查了。在日后版本中也会优化框架的报错、日志机制,抱歉。

#A3 是的,Core-Biu 中只是将其实例化并登陆,但后续的相关操作都是在 Plugin 中进行的(作品搜索的具体实现)。

PixivBiu 并没有使用官方的 API 来实现热度搜索,只是用了最原始的办法:一次性多抓几页,将结果排序而已。所以程序有提供相关设置,可以指定一次性抓取的页数。

Azureki commented 3 years ago

感谢您的详细回复。我再试试看。

端口被使用

昨晚没仔细测试,今天发现只在开启debug模式时会提示端口已被占用。
isPortInUse__preCheck 中打印相应的信息,发现不开启debug模式,信息只在开头打印了一次,而debug模式在开头和结束都打印一次。

附上debug模式下的输出:

print 运行前检测
print 检测端口:4001
[pixivbiu] byPassSni api 登录成功
[pixivbiu] 初始化完成
------------
 PixivBiu 
-
运行: http://127.0.0.1:4001/ (将地址输入现代浏览器即可使用)
版本: 200009 (最新)
API 类型: byPassSni
图片服务器: https://i.pixiv.cat/
下载保存路径: 程序目录/downloads/{KT}/
-
 Biu 
------------
 * Serving Flask app "run" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:4001/ (Press CTRL+C to quit)
 * Restarting with stat
print 运行前检测
print 检测端口:4001
现端口已被占用,请修改 config.yml 中 sys-host 配置。
按任意键退出...

但是我不知道为什么会这样,代码中 debug 只在 app.run 出现了一次。

连接

我之前没有描述清楚。看不到图是指使用时(搜索、排行榜、收藏)一直在加载(转圈),但并没有显示出图片(图片的位置也没有)。昨晚测试时没有错误信息(这也是为什么开启debug模式,然而开启之后却提示端口被占用),今天测试时才有,但不能复现错误信息。
我也以为是网络有问题,然而奇怪的是,不开启代理时,我直接使用 pixivpy 的 byPassSni 登录,却可以正常使用其 api……
有个信息我不知道是否有用:昨晚 PixivBiu 没有报错,使用 pixivpy 的 byPassSni 登录,获取到的 ip 是 210.140.131.219。今天 PixivBiu 错误信息中连接的 ip 是 210.140.131.219,使用 pixivpy 获取的 ip 是 210.140.131.223,pixivpy 今天依然可以使用。
不知今天报错是不是因为无法连接 210.140.131.219 ?但是不清楚为什么不报错时也无法使用……

附上今天的错误信息(很长):

[pixivbiu] byPassSni api 登录成功
[pixivbiu] 初始化完成
------------
 PixivBiu 
-
运行: http://127.0.0.1:4001/ (将地址输入现代浏览器即可使用)
版本: 200009 (最新)
API 类型: byPassSni
图片服务器: https://i.pixiv.cat/
下载保存路径: 程序目录/downloads/{KT}/
-
 Biu 
------------
 * Serving Flask app "run" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
[system] Plugin  api/biu/get/idmarks  failed to run
[ERROR] requests GET https://210.140.131.219/v1/user/bookmarks/illust error: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 426, in _make_request
    six.raise_from(e, None)
  File "", line 3, in raise_from
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1322, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 303, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 272, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 403, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3.8/site-packages/urllib3/packages/six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 426, in _make_request
    six.raise_from(e, None)
  File "", line 3, in raise_from
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1322, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 303, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 272, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/azuki/.local/lib/python3.8/site-packages/pixivpy3/api.py", line 58, in requests_call
    return self.requests.get(url, params=params, headers=headers, stream=stream, **self.requests_kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/home/azuki/.local/lib/python3.8/site-packages/requests_toolbelt/adapters/host_header_ssl.py", line 43, in send
    return super(HostHeaderSSLAdapter, self).send(request, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/azuki/projects/github/PixivBiu/app/platform.py", line 23, in process
    r = self.PLUGINS[cmd](self).pRun(cmd)
  File "/home/azuki/projects/github/PixivBiu/app/plugin/biu/get/idmarks.py", line 33, in pRun
    "rst": self.gank(args["ops"], args["fun"].copy()),
  File "/home/azuki/projects/github/PixivBiu/app/plugin/biu/get/idmarks.py", line 52, in gank
    t = self.MOD.biu.apiAssist.user_bookmarks_illust(**argg)
  File "/home/azuki/.local/lib/python3.8/site-packages/pixivpy3/aapi.py", line 137, in user_bookmarks_illust
    r = self.no_auth_requests_call('GET', url, params=params, req_auth=req_auth)
  File "/home/azuki/.local/lib/python3.8/site-packages/pixivpy3/aapi.py", line 46, in no_auth_requests_call
    return self.requests_call(method, url, headers, params, data)
  File "/home/azuki/.local/lib/python3.8/site-packages/pixivpy3/api.py", line 66, in requests_call
    raise PixivError('requests %s %s error: %s' % (method, url, e))
pixivpy3.utils.PixivError: requests GET https://210.140.131.219/v1/user/bookmarks/illust error: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

以上为今天上午测试内容,本来下午想继续测试连接问题,但无法登录了…… https://github.com/upbit/pixivpy/issues/158

txperl commented 3 years ago

端口被使用问题 抱歉,这是一个程序 BUG,之前加入端口检测功能后没有在 Debug 模式下测试... 因为 Flask Debug 模式初始化时会启动一个子进程,以便在代码变更时重新加载,所以会出现端口占用。((

已在最新版本中修复。

连接问题 如果 byPassSni 模式可以使用,可以正常显示结果图片,那说明不是浏览器前端兼容问题,本地网络也畅通。但使用代理时就会出现错误,看报错信息,我猜测肯能是代理服务器的问题...? 可以尝试换几条线路试试,注意多条线有相同中转的情况。

无法登陆问题 之前测试都是使用 token 进行的,所以我也才知道有这个问题... 暂时无法给出解决方案,请等后续更新。

😄 感谢提供了这么详细的测试与反馈!

Azureki commented 3 years ago

哦我可能写得太乱了。

我说使用 pixivpy 的api指的是另外测试 pixivpy,不使用 PixivBiu。
通过 pixivpy 的 byPassSni 登录,并使用搜索、收藏等 api 可以获取到图片的地址等信息,而 PixivBiu 使用时一直在转圈(但也没有错误信息)。 我一直都没用代理…因为sock5代理用不了嘛。我的配置文件中代理是noapi 也从 public 修改成了 byPassSni

目前无法登录,等可以登录之后再试试吧。

txperl commented 3 years ago

好吧,我可能知道了。((

这种情况可能是浏览器前端兼容问题,请问现在用的是什么浏览器?可以试一下最新的现代浏览器。

要支持 socks5 只需要安装一下 PySocks 就好了,新的 requirements 中已经包含了。