I was trying to run the following code but it shows me an error
Traceback (most recent call last): File "/home/python/flask_ass.py", line 1, in from flask import Flask,requests,json ImportError: cannot import name 'requests'
My code snippet is
from flask import Flask, requests, json
# api key=03a84ce64ef242418d262c11a57248de
url = ('https://newsapi.org/v2/top-headlines?'
'country=us&'
'apiKey=03a84ce64ef242418d262c11a07248de')
params = {'id': 21,
'name': 'John'}
response = requests.get(url, params=params)
r_dict = response.json()
# print(r_dict)
# print(response.status_code())
print(r_dict['articles'][1]['title'])
# print(response.text)
app = Flask(__name__)
@app.route("/")
def hell():
return r_dict
requestsis not part of Flask and can not be imported from there. It's a stand-alone package. - Klaus D.