调用API函数时候,报None type object的错误

#环境:colab.google,主机:mac,没有装pycharm#
!pip install producthunt

from producthunt import ProductHunt
api_key = ‘这里填的是api key’
ph = ProductHunt(api_key)

#截止以上都没问题#

ph.get_daily()

#直到运行函数就会报错,并且在navigator运行也报一样的错#

Jason990420
最佳答案

Maybe you got

data = {'data': None,
 'errors': [{'error': 'invalid_oauth_token',
             'error_description': 'Please supply a valid access token. Refer '
                                  'to our api documentation about how to '
                                  'authorize an api request. Please also make '
                                  'sure you require the correct scopes. Eg '
                                  '"private public" for to access private '
                                  'endpoints.'}]}

so data.get('data', {}) is None, then data.get('data', {}).get will get

AttributeError: 'NoneType' object has no attribute 'get'
1个月前 评论
讨论数量: 1
Jason990420

Maybe you got

data = {'data': None,
 'errors': [{'error': 'invalid_oauth_token',
             'error_description': 'Please supply a valid access token. Refer '
                                  'to our api documentation about how to '
                                  'authorize an api request. Please also make '
                                  'sure you require the correct scopes. Eg '
                                  '"private public" for to access private '
                                  'endpoints.'}]}

so data.get('data', {}) is None, then data.get('data', {}).get will get

AttributeError: 'NoneType' object has no attribute 'get'
1个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!