谁能给我解释一下为什么我得到了422错误?
我有来自Postman的JSON,现在我正试着在Locust中发送这个JSON。BUt所有的时间,我得到422错误。
这是来自Postman的JSON:
data = {"startDate": "2020-10-01T00:00:00.000Z",
"endDate": "2020-10-11T00:00:00.000Z",
"id": 117,
"title": "Job Postmanowy Contractora 156",
"desc": "Backendowe opowiastki",
"active": true,
"isDraft": false,
"isPaused": false,
"isBlocked": false,
"locationPayload": "{\"locationType\":\"locationPlace\",\"locationName\":\"Wałbrzych, Dolnośląskie, Poland\",\"locationPlace\":\"place.8245570224125220\",\"locationRegion\":\"region.11228101935550230\",\"locationCountry\":\"country.5811537771766020\"}",
"locationName": "Minneapolis, MN, USA",
"workingHours": "No matter",
"employmentType": "other",
"assignmentType": "indi",
"gender": "both",
"minWorkers": 3,
"maxWorkers": 5,
"minHeight": 10,
"minWeight": 10,
"maxHeight": 180,
"maxWeight": 80,
"minAge": 18,
"maxAge": 25,
"minWage": 20,
"maxWage": 20,
"wageFrequency": "per hour",
"paymentType": "credit card",
"updatedBy": null,
"createdAt": "2020-07-10T12:34:18.000Z",
"updatedAt": "2020-07-10T12:34:20.000Z",
"deletedAt": null,
"userId": 100,
"canApply": false,
"applied": false,
"applicationStatus": null,
"isMine": true,
"status": "future",
"isFavourite": false,
"applications": {"applied": 0, "accepted": 0, "declined": 0},
"isEditable": true,
"location": {},
"user": {"id": 100,
"fullName": "Con SzamsungS9 1",
"companyName": "", "rating": null,
"avatar": "files/3859ca8b6afde6838cf3b6fce356dbaf67359d252f5670d87d6a61e3c7149377image-e4212eac-e0b8-40e7-b009-d3907bf51a5a.jpg"},
"languages": ["German", "English", "Spanish", "Hindi", "Italian", "Polish"],
"highlights": ["high-voltage", "heavy materials"]}使用小写boolean时,我有创建参数的提示,当我更改为大写时,我有422个参数。
这就是我想发布我的JSON的方式
self.client.post('/v1/jobs/drafts/', headers=self.headers, data=json.dumps(data))发布于 2020-07-10 21:40:38
这应该是可行的:
首先,使用python语法将json创建为字典:
data = {"startDate": "2020-10-01T00:00:00.000Z",
"endDate": "2020-10-11T00:00:00.000Z",
"id": 117,
"title": "Job Postmanowy Contractora 156",
"desc": "Backendowe opowiastki",
"active": True,
"isDraft": False,
"isPaused": False,
"isBlocked": False,
"locationPayload": "{\"locationType\":\"locationPlace\",\"locationName\":\"Wałbrzych, Dolnośląskie, Poland\",\"locationPlace\":\"place.8245570224125220\",\"locationRegion\":\"region.11228101935550230\",\"locationCountry\":\"country.5811537771766020\"}",
"locationName": "Minneapolis, MN, USA",
"workingHours": "No matter",
"employmentType": "other",
"assignmentType": "indi",
"gender": "both",
"minWorkers": 3,
"maxWorkers": 5,
"minHeight": 10,
"minWeight": 10,
"maxHeight": 180,
"maxWeight": 80,
"minAge": 18,
"maxAge": 25,
"minWage": 20,
"maxWage": 20,
"wageFrequency": "per hour",
"paymentType": "credit card",
"updatedBy": None,
"createdAt": "2020-07-10T12:34:18.000Z",
"updatedAt": "2020-07-10T12:34:20.000Z",
"deletedAt": None,
"userId": 100,
"canApply": False,
"applied": False,
"applicationStatus": None,
"isMine": True,
"status": "future",
"isFavourite": False,
"applications": {"applied": 0, "accepted": 0, "declined": 0},
"isEditable": True,
"location": {},
"user": {"id": 100,
"fullName": "Con SzamsungS9 1",
"companyName": "", "rating": None,
"avatar": "files/3859ca8b6afde6838cf3b6fce356dbaf67359d252f5670d87d6a61e3c7149377image-e4212eac-e0b8-40e7-b009-d3907bf51a5a.jpg"},
"languages": ["German", "English", "Spanish", "Hindi", "Italian", "Polish"],
"highlights": ["high-voltage", "heavy materials"]}然后使用关键字json而不是data
self.client.post('/v1/jobs/drafts/', headers=self.headers, json=data)来源:
https://docs.locust.io/en/stable/api.html#locust.clients.HttpSession.post
发布于 2020-07-14 03:04:01
将JSON存储在.json文件中,现在您可以直接从该文件读取并运行测试。适用于我:)
import json
@task(1)
def my_task(self):
file_name = 'my_json.json'
with open(file_name) as json_file:
post_data = json.load(json_file)
self.client.post('/v1/jobs/drafts/', data=json.dumps(post_data),
headers=my_headers)https://stackoverflow.com/questions/62835294
复制相似问题