Issue with Invocation to Python Services in Dapr

Mhd Issa 0 Reputation points
2025-01-13T17:17:41.02+00:00

Dear Microsoft Dapr Support Team,

I hope this message finds you well.

I am encountering an issue when attempting to invoke Python services using Dapr. The following error is appearing:

java
Copy code
code 

Upon investigating, it seems this error occurs when order information is incomplete or missing. However, despite extensive attempts to resolve this, including referencing the official Dapr documentation and implementing the sample code provided, the error persists.

As a temporary workaround, I am routing the request through a gateway, but this is not a viable long-term solution. I plan to revisit this issue after addressing higher-priority tasks and bugs.

Could you provide any insights or guidance on the root cause and how to resolve this issue? Your support would be greatly appreciated.

this is my code :

with DaprClient() as d:
            #last_headers = [("invoker-app-id", "filemanagement"),("data","data")]
            if method.lower() == "get":
                response = d.invoke_method(
                    appid,
                    path,
                    data='{"message":"Hello World"}',
                    metadata=None,
                    content_type="application/json",
                )
            else:
                response = d.invoke_method(
                    appid, path, data=payload, metadata=None, http_verb="post"
                )

and this is the view that i received the invoke :

class Test1(APIView):
    parser_classes = [JSONParser]
    def post(self, request, *args, **kwargs):
                print(request.data)

but the request.data is empty

Thank you in advance for your assistance.

Best regards, Mhd Issa

Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,155 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 5,575 Reputation points Microsoft Employee
    2025-01-17T21:17:28.38+00:00

    Hello @Mhd Issa

    Based on the information you provided; it seems that you are encountering an issue when invoking Python services using Dapr. The error message you provided is not clear enough to identify the root cause of the issue.

    However, I can provide you with some general guidance that may help you resolve the issue. Firstly, it is important to ensure that the Dapr runtime is running and properly configured.

    You can check the status of the Dapr runtime by running the following command in your terminal:

    dapr status -k
    
    

    If the Dapr runtime is not running, you can start it by running the following command:

    dapr run --app-id --app-port
    

    Secondly, it is important to ensure that the Dapr client is properly configured in your Python code. You can use the following code snippet to create a Dapr client:

    from dapr.clients import DaprClient
    with DaprClient() as d: 
    # Your Dapr client code here
    

    Thirdly, it is important to ensure that the payload you are sending to the Dapr service is properly formatted. You can use the following code snippet to send a POST request to a Dapr service:

    with DaprClient() as d:
    response = d.invoke_method( app_id='', method_name='', data='', metadata=None, content_type='application/json' )
    

    Lastly, it is important to ensure that the view you are using to receive the invoke request is properly configured. You can use the following code snippet to receive an invoke request in a Django view:

    from django.http import HttpResponse
    from dapr.ext.clients import DaprActorClient
    def my_view(request):
    if request.method == 'POST':
    	data = request.body
    	# Your view code here
    	return HttpResponse(status=200)
    else: 
    	return HttpResponse(status=405)
    

    I hope this information helps you resolve the issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.