0

I want to post JSON data by requests. I used Fiddler to inspect the data transmission. The data I want to post is below:

{'configList': [{'ccolumn': 'gender',
   'ctable': 'arc_mxdata_operator',
   'cvalue': '男',
   'formula': '包含',
   'integral': 1,
   'integralIfMissing': 0,
   'resultIfMissing': '10'},
  {'ccolumn': 'gender',
   'ctable': 'arc_mxdata_operator',
   'cvalue': '女',
   'formula': '包含',
   'integral': 0,
   'integralIfMissing': 0,
   'resultIfMissing': '10'}],
 'id': 'Sushifaker',
 'infoList': [{'info_formula': '<=', 'info_integral': 5, 'info_result': '30'}],
 'name': 'Submit2018-11-27-19-18-30',
 'ratio': None,
 'ratioMaxCount': None,
 'type': '10',
 'typeResultStatus': '10'}

I found this data is urlencoded when uploading. So I encode the data in python

data = json.dumps(data, ensure_ascii=False)
rs = requests.post(url, data=data)

The response in rs is failed. I can not post the data. But I found the correct data found in Fiddler is

name=Submit2018-11-27-19-18-30&id=999&ratio=&ratioMaxCount=&configList=%5B%7B%22ctable%22%3A%22arc_mxdata_operator%22%2C%22ccolumn%22%3A%22gender%22%2C%22formula%22%3A%22%E5%8C%85%E5%90%AB%22%2C%22cvalue%22%3A%22%E7%94%B7%22%2C%22integral%22%3A1%2C%22integralIfMissing%22%3A0%7D%2C%7B%22ctable%22%3A%22arc_mxdata_operator%22%2C%22ccolumn%22%3A%22gender%22%2C%22formula%22%3A%22%E5%8C%85%E5%90%AB%22%2C%22cvalue%22%3A%22%E5%A5%B3%22%2C%22integral%22%3A0%2C%22integralIfMissing%22%3A0%7D%5D&infoList=%5B%7B%22info_formula%22%3A%22%3C%3D%22%2C%22info_integral%22%3A5%2C%22info_result%22%3A%2230%22%7D%5D&type=10&typeResultStatus=10&ruleType=0  

The difference between two data is ratio=&ratioMaxCount=, it's looks like a parameters in a url. I don't know why and how to get a correct data to post.

Update: After reading doc from urllib and check the difference between two output. I have misused quote and urlencode.

2
  • 1
    Use empty string rather than None? Commented Nov 28, 2018 at 6:08
  • @GarrettKadillak It works. Thank you Commented Nov 28, 2018 at 8:18

1 Answer 1

2

Replace None with ''

That will solve it.

Sign up to request clarification or add additional context in comments.

1 Comment

It's my fault. I am confused with quote and urlencode. After replaceing None with '', it works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.