请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

运行时提示:list indices must be integers, not str

代码:

#coding:utf-8
import requests
import json
url = "http://m.imooc.com/passport/user/login"
data = {
  "username": "18513199586",
  "password": "111111",
  "verify": "",
  "referer": "https://m.imooc.com"
}
res=requests.post(url,data).json()
response_url= res['data']['url'][0]
response_url=response_url+"&callback=jQuery21008240514814031887_1508666806"
cookie=requests.get(response_url).cookies
#cookie=requests.utils.dict_from_cookiejar(cookie) #cookiejar转换为字典
#print cookie
#print cookie['apsid']
url1="http://order.imooc.com/pay/submitorder?jsonpcallback=jQuery111301426289146376727_1535897916059&goods_ids=1082&_=1535897916066"
print requests.get(url1).text
#print requests.get(url1).text

运行结果:

Traceback (most recent call last):

  File "J:/imoocInterface/util/operation_header_cainiao.py", line 12, in <module>

    response_url= res['data']['url'][0]

TypeError: list indices must be integers, not str


代码如截图:

https://img1.sycdn.imooc.com//szimg/5b8bf2e20001956113480553.jpg

https://img1.sycdn.imooc.com//szimg/5b8bf2e20001952709600283.jpg


正在回答

1回答

Mushishi 2018-09-04 14:45:32

你好,你看错误已经告诉你了,list类型你获取值的时候的索引只能是整数不能是str。res['data']['url'][0]

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信