AWS Lambda函数出现'NoneType' object is not iterable错误的排查求助
AWS Lambda函数出现'NoneType' object is not iterable错误的排查求助
大家好,我写了一个AWS Lambda函数,用来调用外部API获取数据并做格式化处理,但运行时抛出了类型错误,提示'NoneType' object is not iterable,折腾了一阵还是找不到问题根源,想请各位帮忙排查下。
以下是我的Lambda函数相关代码片段:
try: with urllib.request.urlopen(api_url) as response: data=json.loads(response.read().decode()) print(json.dumps(data, indent = 4 )) except Exception as e : print(f"error reading data : {e} ") return {"statuscode":"500","body":"Error fetching data"} games_messages = [game_format(game) for game in data]
运行后得到的错误信息如下:
"errorMessage": "'NoneType' object is not iterable", "errorType": "TypeError", "requestId": "11a9a46e-3abe-4f6e-8c38-278c0697238a", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 69, in lambda_handler\n games_messages = [game_format(game) for game in data]\n", " File \"/var/task/lambda_function.py\", line 15, in game_format\n quarter_scores = ', '.join([f\"Q{q['Number']}: {q.get('AwayScore', 'N/A')}-{q.get('HomeScore', 'N/A')}\" for q in quarters])\n" ] }
另外,我从API获取到的数据格式如下(截图):
备注:内容来源于stack exchange,提问作者skavanas
相关产品推荐
相关产品推荐

