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

歌词请求返回Internal Server Error #117

Open
2 tasks done
yuhenghuang opened this issue Jan 21, 2025 · 6 comments
Open
2 tasks done

歌词请求返回Internal Server Error #117

yuhenghuang opened this issue Jan 21, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@yuhenghuang
Copy link

提交Issue之前,你应当知道:

  • Issue是用于快速定位和解决问题的,而不是这个项目的评论区。
  • 一个简明扼要的标题可以快速定位关键信息,标题不需要长篇大论,也不应过于宽泛。

问题描述

日志中报错的地方

2025/01/22 00:41:29 stdout TypeError: string indices must be integers, not 'str'
2025/01/22 00:41:29 stdout ~~~~~~~~~~~~~~~~~~~^^^^^^^^^
2025/01/22 00:41:29 stdout song_info: list[dict] = song_info["result"]["songs"]
2025/01/22 00:41:29 stdout File "/app/mod/searchx/netease.py", line 196, in search_track

看起来是在处理网易云返回的信息的时候遇到了之前不一样的结果

代码本来希望song_info["result"]dict,结果返回的是字符串

等了2个月也没修复.难道只有我遇到这个致命的问题??

P.S. 因此还在用老旧的1.5.2版,歌词也只有酷狗

请求与响应

Request Address: http://我的服务器:28883/api/v1/lyrics/advance

Response Code: 500

# header
access-control-allow-headers: Content-Type,Authorization
access-control-allow-origin: *
content-length: 265
content-type: text/html; charset=utf-8
date: Tue, 21 Jan 2025 15:51:32 GMT
server: waitress

# body
<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

日志文件

基本完整的整个报错stack

date stream content
2025/01/22 00:41:29 stdout TypeError: string indices must be integers, not 'str'
2025/01/22 00:41:29 stdout ~~~~~~~~~~~~~~~~~~~^^^^^^^^^
2025/01/22 00:41:29 stdout song_info: list[dict] = song_info["result"]["songs"]
2025/01/22 00:41:29 stdout File "/app/mod/searchx/netease.py", line 196, in search_track
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return await search_track(session, title=title, artist=artist, album=album)
2025/01/22 00:41:29 stdout File "/app/mod/searchx/netease.py", line 154, in a_search
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return future.result()
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/asyncio/base_events.py", line 684, in run_until_complete
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return self._loop.run_until_complete(task)
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return runner.run(main)
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return asyncio.run(a_search(title=title, artist=artist, album=album))
2025/01/22 00:41:29 stdout File "/app/mod/searchx/netease.py", line 264, in search
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return func(*args, **kwargs)
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/site-packages/mygo/devtools/init.py", line 51, in inner
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout res: list = task.search(title, artist, album)
2025/01/22 00:41:29 stdout File "/app/mod/searchx/init.py", line 11, in request
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout result = self.fn(*self.args, **self.kwargs)
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
2025/01/22 00:41:29 stdout raise self._exception
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return self.__get_result()
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 449, in result
2025/01/22 00:41:29 stdout future.result()
2025/01/22 00:41:29 stdout File "/app/mod/searchx/init.py", line 23, in search_all
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout lyrics_list = searchx.search_all(title, artist, album)
2025/01/22 00:41:29 stdout File "/app/api/lyrics.py", line 87, in lrc_json
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return ensure_sync(fn)(*args, **kwargs)
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/site-packages/flask_caching/init.py", line 175, in _call_fn
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout rv = self._call_fn(f, *args, **kwargs)
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/site-packages/flask_caching/init.py", line 399, in decorated_function
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return func(*args, **kwargs)
2025/01/22 00:41:29 stdout File "/app/mod/auth/init.py", line 20, in wrapper
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout rv = self.dispatch_request()
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout rv = self.handle_user_exception(e)
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
2025/01/22 00:41:29 stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025/01/22 00:41:29 stdout response = self.full_dispatch_request()
2025/01/22 00:41:29 stdout File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app

系统信息

群晖DS223 (arm64)

Docker部署的lrcapi 版本1.5.7

补充信息

可能的解决方案: 更新网易云返回结果处理的逻辑

@yuhenghuang yuhenghuang added the bug Something isn't working label Jan 21, 2025
@HisAtri
Copy link
Owner

HisAtri commented Jan 21, 2025

@TooAndy

@LyingDoc
Copy link

LyingDoc commented Feb 6, 2025

@TooAndy

大佬,我看了你里面的封面接口也是一个域名接口,我想问下你的这个项目有吗?我准备单独部署

@TooAndy
Copy link
Contributor

TooAndy commented Feb 6, 2025

抱歉,很久没看邮箱。
我确实没遇到过这个问题,能提供一下具体的查询的条件吗?@yuhenghuang

@TooAndy
Copy link
Contributor

TooAndy commented Feb 6, 2025

song_info["result"] 是字符串, 是不是因为你使用了全局科学上网? 网易云音乐在墙外返回的内容是加密的. 请确保lrcapi不要在墙外使用.

@yuhenghuang
Copy link
Author

@TooAndy

song_info["result"] 是字符串, 是不是因为你使用了全局科学上网? 网易云音乐在墙外返回的内容是加密的. 请确保lrcapi不要在墙外使用.

破案了。我肉身在墙外…
这bug确实和程序没关系了,难怪issue都没人提。我之后挂翻回来的代理再使用吧

感想指点

PS 把api换成/api/v1/lyrics/single 似乎就没有这个问题了

@yuhenghuang
Copy link
Author

yuhenghuang commented Feb 7, 2025

@TooAndy

我在走了国内代理之后问题就解决了.


以下是feature request

能不能考虑一下在程序启动项里增加proxy的设置.

目前我使用的方法是在酷狗和网易的session创建里增加trust_env=True

async with aiohttp.ClientSession(trust_env=True) as session

来使用环境变量定义的http_proxy

# 我在host上部署的国内代理
HTTP_PROXY=http://host.docker.internal:9099
# 这两个是程序内置的域名,不需要代理
NO_PROXY="lrc.cx,jsdelivr.com"

docker-compose.yml里面的话主要是增加以下3行

    environment:
      - HTTP_PROXY=http://host.docker.internal:9099
      - NO_PROXY="lrc.cx,jsdelivr.com"
    extra_hosts:
      - host.docker.internal:host-gateway

这个方法在docker里还好,在本机部署的话会和本地的环境变量起冲突多少有点不合理.

不过这是尽量不改太多地方的代码才用的方法. 能在py文件里实现肯定是可以不影响系统的

PS 如果有同样的倒霉蛋也可以参考我的方法

  • 搞一个翻回国内的梯子
  • 自己改两行python代码
  • 改一下docker-compose.yml的设置

就能解决.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants