m0_55935452
我是要成为python的男人
2021-03-11 20:52
采纳率: 100%
浏览 52

python的json报错

import requests
import json

if __name__=="__main__":
    url = 'https://movie.douban.com/j/chart/top_list?'
    param = {
    'type:'' 24'
    'interval_id':' 100:90',
    'action':'',
    'start':'0',#从库中的第几部电影开始取
    'limit':'20',#一次请求取出的个数
    }
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'
    }
    response = requests.get(url=url,params=param,headers=headers)

    list_date = response.json()

    fp = open('E:\pythonlearn./douban.json','w',encoding='utf-8')
    json.dump(list_date,fp=fp,ensure_ascli=False)

    print('over!!')

Traceback (most recent call last):
  File "E:\pythonlearn\learn\learn2.py", line 21, in <module>
    json.dump(list_date,fp=fp,ensure_ascli=False)
  File "D:\python3.9.0a4(64-bit)\lib\json\__init__.py", line 173, in dump
    iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
TypeError: __init__() got an unexpected keyword argument 'ensure_ascli'

Process finished with exit code 1

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • funny123
    coagenth 2021-03-11 21:42
    已采纳

    参数名写错了,应该是ensure_ascii,不是ensure_ascli

    点赞 1 评论
  • qq_43656607
    放风喽 2021-03-11 21:23
    json.dumps('凉凉', ensure_ascii=False)
    json.dump(list_date,fp=fp,ensure_ascli=False)
    
    点赞 评论

相关推荐