马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小弟用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[0])
# print("type(Offer_Successful): ",type(Offer_Successful))
Offer_Failed = json.loads(Offer[1])
# 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/")
你传的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."
}
|