求助:Google Cloud中AttributeError致BQ无数据(Facebook Ads连接器)
解决AttributeError: 'NoneType' object has no attribute 'format' 问题
错误原因
你代码中的异常处理语句存在调用逻辑错误:logger.error('request to currencylayer error: {}').format(e)
这里logger.error()执行后返回的是None,你试图对None对象调用.format()方法,直接触发了AttributeError,同时会导致异常处理逻辑失效,进而中断数据写入流程,最终造成BigQuery表无数据写入。
修正后的代码
将字符串格式化操作放在logger.error()的参数内部即可:
except requests.exceptions.RequestException as e: logger.error('request to currencylayer error: {}'.format(e)) return e
你也可以使用更简洁的f-string写法:
except requests.exceptions.RequestException as e: logger.error(f'request to currencylayer error: {e}') return e
内容的提问来源于stack exchange,提问作者kubri81
相关产品推荐
相关产品推荐

