Search code examples
pythondjangorestapipypi

CryptoControl - Python Crypto News API Integration in Python Django


My code is--

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})

I am integrating CryptoControl - Python Crypto News API in django but i am getting this error:

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:\Users\sachin.parashar\Envs\newsbit\lib\site-packages\crypto_news_api\__init__.py in _fetch, line 28
Python Executable:  C:\Users\sachin.parashar\Envs\newsbit\Scripts\python.exe
Python Version: 3.7.3

Can anyone help me on this as I am new to python with django framework. Also I have installed -- pip install crypto-news-api and pip install requests.


Solution

  • You can use:

    data= requests.get("__You URL__")
    data_content= json.loads(data.content)
    return render(request, '__you template here__', 'data':data_content})