小编Ant*_*296的帖子

如何修复'AttributeError:'dict'对象没有属性...'Python断言中的错误

我正在使用请求模块和python assert关键字设置请求断言,但是

AttributeError:'dict'对象没有属性'documentation_url'

当我尝试在json响应中声明字符串时。我如何在json响应中声明某些内容,当条件为true时,它应该打印出某些内容?

import requests
import pprint

URL = 'https://github.com/timeline.json'

def get_github_json(URL):
    response = requests.get(URL).json()
    return response

assert get_github_json(URL).documentation_url == 'https://developer.github.com/v3/activity/events/#list-public-events'
Run Code Online (Sandbox Code Playgroud)

json响应如下所示:

{'documentation_url': 'https://developer.github.com/v3/activity/events/#list-public-events',
 'message': 'Hello there, wayfaring stranger. If you’re reading this then you '
            'probably didn’t see our blog post a couple of years back '
            'announcing that this API would go away: http://git.io/17AROg Fear '
            'not, you should be able to get what you need from the shiny new '
            'Events API instead.'
}
Run Code Online (Sandbox Code Playgroud)

json assert python-3.x

1
推荐指数
1
解决办法
1689
查看次数

标签 统计

assert ×1

json ×1

python-3.x ×1