@@ -416,9 +416,13 @@ def _create_events(self, target_project, res_id,
416
416
# which contains a list of items
417
417
res_pl = res_payload [res_spec .type_name ]
418
418
req_pl = None
419
+ # Ensure request has a JSON body before accessing request.json
419
420
if self ._payloads_enabled and res_spec .payloads ['enabled' ] \
420
- and request .content_type == 'application/json' :
421
- req_pl = iter (request .json .get (res_spec .type_name ))
421
+ and request .content_type == 'application/json' \
422
+ and request .content_length is not None \
423
+ and request .content_length > 0 :
424
+ req_pl_data = request .json
425
+ req_pl = iter (req_pl_data .get (res_spec .type_name ))
422
426
423
427
# create one event per item
424
428
for subpayload in res_pl :
@@ -474,7 +478,9 @@ def _create_events(self, target_project, res_id,
474
478
if event and request .method [0 ] == 'P' \
475
479
and self ._payloads_enabled \
476
480
and res_spec .payloads ['enabled' ] \
477
- and request .content_type == 'application/json' :
481
+ and request .content_type == 'application/json' \
482
+ and request .content_length is not None \
483
+ and request .content_length > 0 :
478
484
self ._attach_payload (event , request .json , res_spec )
479
485
480
486
events = [event ]
0 commit comments