我将JSON数据存储在变量中data.
我想将其写入文本文件进行测试,因此我不必每次都从服务器获取数据.
目前,我正在尝试这个:
obj = open('data.txt', 'wb')
obj.write(data)
obj.close
Run Code Online (Sandbox Code Playgroud)
我收到错误:
TypeError: must be string or buffer, not dict
如何解决这个问题?
我确实试图找到问题的答案,但不知道该怎么办。我发现了以下问题,但他们没有帮助我。问题1、问题2、文档
\n\n我使用的不同函数得到了不同的值。有时None值
\nTypeError: Object of type \'method\' is not JSON serializable
有时\nAttributeError: \'str\' object has no attribute \'status_code\'和\n而这个
\nTypeError: \'method\' object is not iterable
但我仍然没有找到解决我的问题的解决方案。\n这是我的页面模型,它InlinePanel从另一个类获取一些数据:
class ScreencastPage(Page):\n content_panels = Page.content_panels + [\n InlinePanel(\n \'groupstage_screencast_relationship\', label="Choose Teams",\n panels=None, max_num=2),\n ]\n\n parent_page_types = [\'home.HomePage\']\n\n def matches(self):\n matches = [\n n.match for n in self.groupstage_screencast_relationship.all()\n ]\n\n return matches\n\n def serve(self, request):\n if request.is_ajax():\n # TODO Convert self.mathes …Run Code Online (Sandbox Code Playgroud)