python-3.x - 当我在 Python3 中使用默认获取时,如何获得预期的 str 实例,NoneType 发现错误?
问题描述
我看到这个错误:
data["source_domain"], data["ip_address"]])
TypeError: sequence item 3: expected str instance, NoneType found
但这是我导致该错误的代码:
data["segment_user_id"] = record.get("userId", "")
traits = record.get("traits", {})
data.update({
# country_name -> country
trait.replace("country_name", "country"): traits.get(trait, "")
for trait in ["first_name", "last_name", "email", "country_name", "city", "ip_address"]
})
# Add composite key
to_hash = ''.join([data["project_id"], data["anonymous_id"], data["source_system"], data["segment_user_id"],
data["source_domain"], data["ip_address"]])
data["message_composite_key"] = hashlib.md5(to_hash.encode()).hexdigest()
看起来序列号 3data["segment_user_id"]
是无。但这怎么可能呢?我的record.get("userId", "")
代码不是确保始终将其设置为空字符串吗?
解决方案
推荐阅读
- java - 尝试生成 Cucumber 报告时出现 CucumberException
- sorting - Jenkins Pipeline Jira Plugin 排序输入参数
- javascript - 道具验证中缺少功能组件 eslint 'date'
- openwhisk - 如何在 Windows 10 中“制作”OpenWhisk Docker Compose?
- python - Python 2.7:带有 OrderedDict 属性错误的继承
类没有属性“_OrderedDict__root” - python - Django:TypeError:实例(模型对象)之间不支持'<'
- python - 嵌入图像问题
- electron - 在 Electron 中写入打包的应用程序文件夹
- javascript - 将选定数据从一个页面传递到 html 中的另一页面
- arangodb - 尝试连接到 LAN 上的 ArangoDB 服务器时,“请求的地址在其上下文中无效”