我的代码是--
from django.shortcuts import render
from crypto_news_api import CryptoControlAPI
def index(request):
api = CryptoControlAPI("i have entered my api key")
api.enableSentiment()
# Get top news
topNews = api.getTopNews(language = "en")
print(topNews)
#return render(request, 'index.html',{"data":topNews})
我正在 django 中集成CryptoControl
- Python 加密新闻 API,但我收到此错误:
Bad response from the CryptoControl API
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.2.3
Exception Type: Exception
Exception Value:
Bad response from the CryptoControl API
Exception Location: C:Userssachin.parasharEnvsnewsbitlibsite-packagescrypto_news_api__init__.py in _fetch, line 28
Python Executable: C:Userssachin.parasharEnvsnewsbitScriptspython.exe
Python Version: 3.7.3
任何人都可以帮助我,因为我是带有 django 框架的 python 新手。我也安装了 - pip install crypto-news-api
和pip install requests
.
您可以使用:
data= requests.get("__You URL__")
data_content= json.loads(data.content)
return render(request, '__you template here__', 'data':data_content})