urlからjsonを取得できないです。
from django.shortcuts import render from django.http import HttpResponse import requests import json def get_data(): url = 'https://api.github.com/search/repositories?q=stars:%3E=500' response = requests.post(url) resDatas = response.json() print(resDatas)
とコードを書いて、get_dataメソッドを呼び出しました。
その時print(resDatas)で{'message': 'Not Found', 'documentation_url': 'https://docs.github.com/rest'}と出力されました。
一方で、https://api.github.com/search/repositories?q=stars:%3E=500 をブラウザに入力するとjsonのデータが戻ってくるのでデータの取得の方法が悪いのかなと思います。
上記のコードを書くにあたって参考にしたサイトは
https://docs.djangoproject.com/en/3.1/topics/http/sessions/
https://max999blog.com/python-requests-get-post-json-data/
です。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。