Python Forum
Requests gets no out put and no error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Requests gets no out put and no error (/thread-13338.html)



Requests gets no out put and no error - water_fox - Oct-10-2018

using below, I am getting no error, but also no output....anyone able to help?
import requests
import json
import sys


def get_request(api_key):
    api_url='https://api.nasa.gov/planetary/apod'
    r= requests.get(api_url, headers = {"Content-Type": "application/json", "access_key": api_key})
    api_key ='<my api key>'

    print(r.content)
    get_request(api_key)



RE: Requests gets no out put and no error - volcano63 - Oct-10-2018

(Oct-10-2018, 07:52 PM)water_fox Wrote: using below, I am getting no error, but also no output....anyone able to help?
import requests
import json
import sys


def get_request(api_key):
    api_url='https://api.nasa.gov/planetary/apod'
    r= requests.get(api_url, headers = {"Content-Type": "application/json", "access_key": api_key})
    api_key ='<my api key>'

    print(r.content)
    get_request(api_key)
You may start by checking r.status_code and r.reason


RE: Requests gets no out put and no error - buran - Oct-10-2018

If that is all your code, you just define the get_request() function but never call it. Note that lines#9 and 12 are indented and are in fact part of function itself. Unindent lines#9 and 12 one level. The print should remain part of the function.

import requests
import json
import sys
 
 
def get_request(api_key):
    api_url='https://api.nasa.gov/planetary/apod'
    r= requests.get(api_url, headers = {"Content-Type": "application/json", "access_key": api_key})
    print(r.content)


api_key ='<my api key>'
get_request(api_key)
also if the response is json format, you can use r.json()