cacaoMath / rss_collect_api

登録されたRSSfeedURLリンク先から、選んだジャンルの記事を収集するAPI
https://rss-api.cacaomath.com/redoc
0 stars 0 forks source link

無効なURLが登録されているとfeedparserで処理できない #49

Open cacaoMath opened 1 year ago

cacaoMath commented 1 year ago

rssのurlとして存在しないurlが登録された状態で/rssをするとstatas code 500になる

INFO:     127.0.0.1:43234 - "POST /rss HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/fastapi/applications.py", line 271, in __call__
    await super().__call__(scope, receive, send)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/applications.py", line 118, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "/home/cacaomath/development/python_project/rss_collect_api/./app/main.py", line 168, in read_rss
    return rss_crud.return_rss_articles(
  File "/home/cacaomath/development/python_project/rss_collect_api/./app/crud/rss.py", line 18, in return_rss_articles
    feed_list = rss.get_feed(feed_url_list=feed_url_list)
  File "/home/cacaomath/development/python_project/rss_collect_api/./app/rss/rss.py", line 13, in get_feed
    feed_list = self.__feedparser(feed_url_list)
  File "/home/cacaomath/development/python_project/rss_collect_api/./app/rss/rss.py", line 41, in __feedparser
    return list(map(feedparser.parse, url_list))
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/feedparser/api.py", line 216, in parse
    data = _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/feedparser/api.py", line 115, in _open_resource
    return http.get(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
  File "/home/cacaomath/development/python_project/env/dev_api/lib/python3.10/site-packages/feedparser/http.py", line 147, in get
    if url_pieces.port:
  File "/home/cacaomath/.pyenv/versions/3.10.9/lib/python3.10/urllib/parse.py", line 177, in port
    raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as '-3Yw_Hu7jbSO+:Nsgsq-QMYXwP8at8OznAAjhgB9_SE2n2LHPqSwT9yGlwyBHqyJ'
cacaoMath commented 11 months ago

ダメそうな場合は例外処理ではじく

cacaoMath commented 11 months ago

と思ったら、urlは関係なさそう