Python JSON module has no attribute 'dumps'

前端 未结 10 1857
攒了一身酷
攒了一身酷 2021-01-01 09:14

I am running Python 2.7 (x64 Linux) and trying to convert a dict to a JSON object.

>>> import sys
>>> sys.version_info
sys.ver         


        
10条回答
  •  感动是毒
    2021-01-01 09:34

    This error just occurred for me in a different context, but still one of two things named json. I had named a "view" in Django (a Python function that prepares a response to an HTTP request), in this case a view to handle request for data in json format.

    But I had named the view "json". Bad move. I was mystified when print dir(json) returned a dumps-free response in my view "json" whereas it showed "dumps" as an attribute in a similar view that worked.

    This discussion fixed the problem for me.

提交回复
热议问题