今天在运行自动化的过程中,遇到了 {'message': 'JSON parse error - Expecting value: line 1 column 1 (char 0)', 'code': 'parse_error'}这个的error,各种尝试无果:

请求的数据为json格式:

data = {'code_type': 'send', 'category': 1, 'phone': '13123456784'}

发送请求:requests.post(url,data)

返回结果:{'message': 'JSON parse error - Expecting value: line 1 column 1 (char 0)', 'code': 'parse_error'}

 

之前遇到过,尝试把json格式的数据转换为string,就解决了,今天怎么处理都不行,没法了,向万能的度娘求助,终于解决:

  借助第三方包的帮助,这里使用了demjson的包来处理这个问题

     安装: pip install demjson

     使用: demjson.encode(data)

 demjson有两个主要的方法:

  •   encode  编码,将对象转换为json
  •   decode   解码,将json转化为对象

相关文章:

  • 2021-08-08
  • 2021-06-13
  • 2023-03-22
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-01
  • 2022-12-23
  • 2021-07-11
  • 2021-08-23
  • 2021-04-02
  • 2022-12-23
相关资源
相似解决方案