【问题标题】:Why wont the NASA pictures display?为什么不显示 NASA 图片?
【发布时间】:2021-03-06 08:41:28
【问题描述】:

图片不显示。代码执行得很好。我拿出了api密钥。

def gimmePictures(num):
    for n in range(0,num):
        now = datetime.datetime.now()
        day4Pictures= now - datetime.timedelta(days = n)
        data = {'api_key':'', 
         'date':day4Pictures.date()}
        print(data)
        # using the paramas argument in our request
        result =  requests.get('https://api.nasa.gov/planetary/apod',params=data)
        # create a dictionary for yesterday's picture
        dict_day = result.json()
        print(dict_day['date'])
        Image(dict_day['url'])
gimmePictures(10)

【问题讨论】:

  • 欢迎来到 SO!您确定要循环调用gimmePictures(10) 吗?似乎这会炸毁堆栈。 gimmePictures 从未被调用过,也没有数据被添加到绘图中,因此plt.show 没有显示任何内容也就不足为奇了(实际调用该函数也缺少括号)。
  • 谢谢!我做了更改,但我仍然没有照片。我认为 plt.show 是一个很长的镜头哈哈。
  • 更新后完全没有绘图代码了。如果不导入 matplotlib 和 showing the plot,则无法创建绘图。见this tutorial

标签: api


【解决方案1】:

How can I display an image from a file in Jupyter Notebook?

def gimmePictures(num):
    listofImageNames=[]
    for n in range(0,num):
        now = datetime.datetime.now()
        day4Pictures= now - datetime.timedelta(days = n)
        data = {'api_key':'dcS6cZ9DJ4zt9oXwjF6hgemj38bNJo0IGcvFGZZj', 'date':day4Pictures.date()}
        # using the paramas argument in our request
        result =  requests.get('https://api.nasa.gov/planetary/apod',params=data)
        # create a dictionary for yesterday's picture
        dict_day = result.json()
        listofImageNames.append(dict_day['url'])
    for imageName in listofImageNames:
        display(Image(imageName))
gimmePictures(10)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多