Receiving Empty request.data When Invoking a Python Service Using Dapr: Bad Request Syntax (400)
I am encountering an issue while invoking a Python service using Dapr. The invocation consistently results in the following error:
code 400, message Bad request syntax ('4')
After investigating, I found that the error might be related to incomplete or missing order information. However, despite implementing the sample code provided in the Dapr documentation and making several adjustments, the issue persists.
Observed Issue
When invoking the service, request.data
on the receiving end is always empty.
As a temporary workaround, I routed the request through a gateway, which worked. However, this is not a sustainable solution for the long term.
Environment Details
Dapr SDK version: 1.12.1 (Python)
Dapr runtime version: 1.12.5
Deployment platform: Azure containers
Invocation method: Service-to-service using Dapr HTTP API
Attempts to Solve
Verified headers and content type (
application/json
) in the request.Tried different payload formats (stringified JSON and Python dictionaries).
Referenced the official Dapr documentation and sample code.
Question
What could be causing
request.data
to be empty on the receiving side?Is there a specific configuration or step I might be missing for service-to-service invocation using Dapr in this environment?
Additional Information
I tried many solutions:
Changing the code.
Using direct information instead of the Dapr library.
Modifying the method to receive data.
Despite all these attempts, the request arrives but without any data in request.data
.
Thank you for any insights or guidance you can provide!
this is my code :
from dapr.clients import DaprClient
import json
with DaprClient() as d:
if method.lower() == "get":
response = d.invoke_method(
appid="filemanagement",
path="api/file_management/test_update",
data='{"message":"Hello World"}',
metadata=None,
content_type="application/json",
)
else:
response = d.invoke_method(
appid="filemanagement",
path="api/file_management/test_update",
data=json.dumps(payload),
metadata=None,
http_verb="post"
)
from rest_framework.views import APIView
from rest_framework.parsers import JSONParser
from rest_framework.response import Response
class Test1(APIView):
parser_classes = [JSONParser]
def post(self, request, *args, **kwargs):
print("Received data:", request.data)
return Response({"status": "success"})