Sending Post to Rasa Webhook

Hi,

I am trying to send a POST request to Rasa inside a Flask function decorator. Using Python requests:

> message = {
> 'sender' : "user",
> 'message': "hi"
> }

requests.post(url, data=json.dumps(message), headers=headers)

I consistently get this error:

‘_io.TextIOWrapper’ object has no attribute ‘dumps’

(I followed documentation for url using webhooks//webhook)

Even when I try without .dumps, I get a similar error:

‘_io.TextIOWrapper’ object has no attribute ‘loads’

Can you please help me?

Hello! :slight_smile:

You mean requests.post(url, data = message) results in object has no attribute 'loads'?

Can you show more of your code please?

@ChrisRahme Yes, that is what I mean.

p = requests.post(url, data=message, headers=headers)
text = p.text
response = json.loads(text)
print(response)

I also get ‘string indices must be integers’ when I dont encode the json…

Any ideas?

Can you show more of your code please?

Do you have a variable named json somewhere?

@ChrisRahme This is all I am doing for the request, json is just the module imported from “import json”, let me know if you have any potential solutions, thanks

I know, but a common mistake that leads to object has no attribute 'loads' is to do somewhere in the code json = ... and thus overriding the library.

Anyway, this error is more related to Python than Rasa. You may have more chances asking on Stack Overflow, but show more of your code there as well please. You have given too little code to trace the mistake.

Thanks @ChrisRahme. I dont have any json = overriding, but I thought it was the way I was calling Rasa server.

The way you’re doing it looks fine for me :confused: