在项目遇到一个错误 :

TypeError: string indices must be integers

由于是返回的接口数据,所以一时也分辨不出是哪里的错,然后我就还原了这样的场景:

unicode_str = u'abcd'
print unicode_str[2]
print unicode_str['mykey']

读取一个unicode编码的字符串的一个不存在的属性,见第三行,然后就会出现上面的错误

所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性:

type(mydict) == type({}) #检查不是字典

如果是字典,再看看有没有这样的属性:mydict.has_key('mykey')  

Python错误:TypeError: string indices must be integers相关推荐

  1. Python 错误:TypeError String Indices Must be Integers 【已解决】

    Python 错误:TypeError String Indices Must be Integers [已解决] 如果你尝试使用字符串值,而不是整数值来访问字典或可迭代对象的值,那么你将收到以下错误 ...

  2. python之解析 yaml配置文件时TypeError: string indices must be integers

    #定义一个SuperLogin登录函数,传递3个形参数 def SuperLogin(lANIP,username, password):driver = webdriver.Chrome()driv ...

  3. 解决TypeError: string indices must be integers, not str

    遇到问题 ExtendValue = {"area": "1","info": "{\"year\": 201 ...

  4. TypeError: string indices must be integers

    1.错误描述 >>> print(st[-1,-6]); Traceback (most recent call last):File "<pyshell#13> ...

  5. python报错 TypeError: string indices must be integers

    所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({})             #检查不是字典 如果是字典,再看看有没有这样的属性: ...

  6. python3 错误string indices must be integers 的解决方法

    这个错误意思是字符串的下标一定要是整数 出这种错误有多种可能,最形象直接的就是: a = '[abc]' print(a['0']) 有点pyhton基础的都知道下标怎么能是字符串'0',必须是整数0 ...

  7. python string indices must be_python报错string indices must be integers,怎么解决?

    展开全部 python报错string indices must be integers解决如下: 在.py文件中写的data={"a":"123"," ...

  8. string indices must be integers错误原因

    string indices must be integers:字符串索引必须是整数 一.使用字符串为索引 a = [1, 2, 3, 4] print(a['0']) '0'为字符串,0才是整形.这 ...

  9. Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法

    Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法 ...

最新文章

  1. C++添加程序到windows的启动项的代码
  2. ansys怎么合并体_亚马逊合并拆分变体实操(干货)-合并
  3. 《剑指offer》第十三题(机器人的运动范围)
  4. java数据类型_JAVA的数据类型
  5. 软件调试学习笔记(三)—— 调试事件的处理
  6. 2019年第十届蓝桥杯 - 省赛 - C/C++大学B组 - I. 后缀表达式
  7. 腾讯云Service Mesh生产实践及架构演进
  8. Jupyter中打印所有结果的解决办法
  9. [Leetcode Week15]Populating Next Right Pointers in Each Node
  10. 14年百度深度学习校招题目
  11. 2021CSP:游记
  12. 云栖大会 | 释放计算弹性,阿里云做了很多
  13. 如何添加评论_亚马逊评论数据分析
  14. 解决Linux下chrome无法播放flash问题
  15. Java中如何删除文件呢?
  16. java8编程入门 pdf_Java8编程入门官方教程(第6版).pdf
  17. 四、OSPF配置实验
  18. Excel 转 PDF 并添加水印
  19. 在Vmware 14 pro 中安装中兴新支点操作系统
  20. Python MD5值破解

热门文章

  1. 什么是倾斜45度的火山图?
  2. 一个函数统一238个机器学习R包,这也太赞了吧
  3. Linux下如何删除长时间不使用的旧文件?
  4. Linux学习 - sed使用
  5. java返回fail_Java集合中的fail-fast(快速失败)机制详解
  6. thinkphp3.2.3在nginx环境下“__PUBLIC__“路径错误、URL跳转路径错误解决方案
  7. linux upgrade tool使用_p4merge的使用
  8. f分布表完整图a=0.05_2019年05月16日,沪深A股股票分析
  9. 前端模板引擎artTemplate---高性能JavaScript模板引擎
  10. python虚拟环境和pyenv_Python多版本管理器pyenv和虚拟环境pyenv-virtualenv的安装设置...