jackfrued / jackfrued/Python-100-Days

关于Day-14里request的用法看不懂,有大神可以帮忙解答么?

Open
#523 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
187k
Forks
55.8k
PR merge metrics
No merged PRs in 30d

Description

rom time import time
from threading import Thread

import requests

class DownloadHanlder(Thread):

def __init__(self, url):
    super().__init__()
    self.url = url

def run(self):
    filename = self.url[self.url.rfind('/') + 1:]
    resp = requests.get(self.url)
    with open('/Users/e2qiuwe/' + filename, 'wb') as f:
        f.write(resp.content)

def main():
# 通过requests模块的get函数获取网络资源
# 下面的代码中使用了天行数据接口提供的网络API
# 要使用该数据接口需要在天行数据的网站上注册
# 然后用自己的Key替换掉下面代码的中APIKey即可
resp = requests.get(
'http://api.tianapi.com/meinv/?key=APIKey&num=268a10eb01d58a13c1a2f5fd920770f8')
# 将服务器返回的JSON格式的数据解析为字典
data_model = resp.json()
for mm_dict in data_model['newslist']:
url = mm_dict['picUrl']
# 通过多线程的方式实现图片下载
DownloadHanlder(url).start()

if name == 'main':
main()

我run的时候报错:KeyError: 'newslist'
我不是很懂这里面
for mm_dict in data_model['newslist']:
url = mm_dict['picUrl']
newslist和picUrl这俩参数代表啥?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Day-14 example and the main() entry point, then inspect the value returned by requests.get(...).json() before the data_model['newslist'] lookup. Done means documenting the response fields used by the loop and clarifying the reported KeyError; no file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.