吾乃段王爷 发表于 2019-10-23 12:04:58

postman传递多行raw数据

小弟用flask开发的时候,用postman传递数据,在body里的raw想传递以下内容,但是一直报错,不知道为什么。
{
        "email":"xxxxxx@qq.com",
        "content":"GOOD DAY SIR/MADAM.

PLS PPSE SUITABLE TONNAGE FOR BELOW CGO :-

ABT 5,000MT-10,000MT SCRAP IN BULK (SF 2.35 WOG)
GYEONGIN(NEARBY INCHON) / PHUMY.
PPT ONWARD (TRY VSL DATE).
CQD BENDS.
PLS ADVS OWS BEST FIO BSS 1/1
2.50% ADC.
GLESS OK.
"
}

报错信息: "message": "Failed to decode JSON object: Expecting ',' delimiter: line 3 column 14 (char 44)"

好像是因为json数据里的换行导致的,这个content内容是个多行数据,是从别处直接复制粘贴过来的。
下面是小弟部分python代码:
class ParseMail(Resource):
    def post(self):
      parser = reqparse.RequestParser()
      parser.add_argument("email",type=str)
      parser.add_argument("content",type=str,help="请输入邮件内容")
      args = parser.parse_args()
      email = args.get("email","")
      email_content = args.get("content","")
      email_content = normalize_content(email_content)
      Offer = split_content(email_content, email=email,source="web")
      Offer_Successful = json.loads(Offer)
      # print("type(Offer_Successful): ",type(Offer_Successful))
      Offer_Failed = json.loads(Offer)
      # print("type(Offer_Failed): ",type(Offer_Failed))
      dict_offer = {}
      # 不为空,则添加进去
      if Offer_Successful:
            dict_offer["offer"] = Offer_Successful
      if Offer_Failed:
            dict_offer["failed"] = Offer_Failed
      
        return dict_offer

api.add_resource(ParseMail,"/email/")

lff 发表于 2019-11-28 10:28:07

你传的json数据换行太多了,换行最好用转义字符
比如:{
      "email":"xxxxxx@qq.com",
      "content":"GOOD DAY SIR/MADAM.\nPLS PPSE SUITABLE TONNAGE FOR BELOW CGO :-\nABT 5,000MT-10,000MT SCRAP IN BULK (SF 2.35 WOG)\nGYEONGIN(NEARBY INCHON) / PHUMY.\nPPT ONWARD (TRY VSL DATE).\nCQD BENDS.\nPLS ADVS OWS BEST FIO BSS 1/1\n2.50% ADC.\nGLESS OK."
}
页: [1]
查看完整版本: postman传递多行raw数据