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
{{ message }}
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
問題の概要
実践編/chapter06/3_Hacker NewsのAPI/hn_submissions.py
の実行時に以下のようなエラーが出ることがあります。
このエラーは取得した投稿のjsonに
descendants
というキーが含まれていない場合に発生します。コードにはこのようなエラーに対応する処理が含まれていないので、プログラムは停止します。
なお同様の問題は saitan-python/やってみよう_実践編/chapter06/6_2_active_discussions.py でも起きる可能性があります。
簡易的な対処法
簡易的な対処法として、エラーが起きる直前のところで投稿の取得をやめてしまえば、プログラムは正常終了します。以下の行で投稿を取得する数を設定しています。
saitan-python/実践編/chapter06/3_Hacker NewsのAPI/hn_submissions.py
Line 13 in 8196a91
ここで
[:30]
となっている数を、エラーが起きる投稿のひとつ前の数まで減らせば、とりあえず動くようになります。(1番目にdescendants
を含まない投稿があるとお手上げですが、、)参考
エラーが起きる直前の出力を見ると、以下のように対象の投稿のidがわかります。
saitan-python/実践編/chapter06/3_Hacker NewsのAPI/hn_submissions.py
Line 15 in 8196a91
を参考にidを埋め込むと対象の投稿のAPI呼び出しのURLがわかります。上記の場合は https://hacker-news.firebaseio.com/v0/item/24347836.json となります。
ブラウザで上記のURLを見てみると、jsonに
descendants
というキーが含まれていないことがわかります。The text was updated successfully, but these errors were encountered: