Home > database >  AttributeError: 'function' object has no attribute 'json'
AttributeError: 'function' object has no attribute 'json'

Time:02-10

I am attempting to code some auto quote image generation code using the PaperQuotes API and Pillow, but this little piece of code is screwing everything up. (I am sorry if the code is bad, I am still a newbie to coding)

Code:

import requests
import os

url = "https://api.paperquotes.com/apiv1/quotes/?lang=en&limit=1&offset=0&order=-likes&page=1&tags=love,life,depression,suicide,sad,lonely"

my_secret = os.environ['authorization']

headers = {
    'authorization': my_secret,
    }

response = requests.get(url, headers=headers).json

info = response.json
print(info["results"]) 

Error:

AttributeError: 'function' object has no attribute 'json' 

I've tried searching Stackoverflow, but I was not able to understand any of the answers I got.

CodePudding user response:

Json its function, not property. Also info = response because you was geted the json.

import requests
import os

url = "https://api.paperquotes.com/apiv1/quotes/?lang=en&limit=1&offset=0&order=-likes&page=1&tags=love,life,depression,suicide,sad,lonely"

my_secret = os.environ['authorization']

headers = {
    'authorization': my_secret,
    }

response = requests.get(url, headers=headers).json()

info = response
print(info["results"])
  • Related