machinebox / issues

Machine Box issues, bugs and feature requests
2 stars 0 forks source link

Empty json return fakebox #49

Closed BehroozMirmolavi closed 5 years ago

BehroozMirmolavi commented 5 years ago

I see there was already an issue, #27 ,on this however it was closed without description. I am having the same issue, I successfully post an api call locally to a running fakebox (manual checker works fine), but the json return to the api is empty.

According to the documentation 'In some cases in HTTP APIs, there may not be a JSON body at all, such as with connectivity issues or other low-level errors.' How might i go about investigating connectivity or other low-level errors? I'm not aware there are any error messages being returned?

Thanks

dahernan commented 5 years ago

Make sure the Accept header is set to application/json, it should work as expected

BehroozMirmolavi commented 5 years ago

Hi, @dahernan
thanks a lot for the quick response. I have confirmed that and can see post request headers are as expected: Headers:

Thanks

dahernan commented 5 years ago

Can you run this curl command?

curl -XPOST -H "Content-Type: application/json" -d '{"title":"Article title goes here","content":"The article content goes here","url":"http://www.bbc.co.uk/news/uk-39657382"}' "http://localhost:8080/fakebox/check"
BehroozMirmolavi commented 5 years ago

Hi,

That worked, thanks so much. Though looking at the headers on the successful command, we have this? Headers:

dahernan commented 5 years ago

Could you provide more details of what are you trying to do? Maybe some code or how are you doing the request? I'm sorry but is quite difficult to help with this level of details

BehroozMirmolavi commented 5 years ago

Yes of course, I am using the /fakebox/check endpoint to analyze a news article, having spun up an instance locally. This example curl works as you suggested:

curl -XPOST -H "Content-Type: application/json" -d '{"title":"Article title goes here","content":"The article content goes here","url":"http://www.bbc.co.uk/news/uk-39657382"}' "http://localhost:8080/fakebox/check"

I'm happy to close this as solving my problem, just a little confused why my initial posts with the correct headers didnt work. I'm working in R to post to the api:

httr::POST("http://localhost:8080/fakebox/check", body = '{"title":"Article title goes here","content":"The article content goes here","url":"http://www.bbc.co.uk/news/uk-39657382"}',accept("application/json"),content_type("charset=utf-8"))

with response

Response [http://localhost:8080/fakebox/check] Date: 2019-03-26 14:45 Status: 200 Content-Type: application/json; charset=utf-8 Size: 84 B { "success": true, "title": {}, "content": { "keywords": [] }, "domain": {}

dahernan commented 5 years ago

You are missing the content type, try:

httr::POST("http://localhost:8080/fakebox/check", body = '{"title":"Article title goes here","content":"The article content goes here","url":"http://www.bbc.co.uk/news/uk-39657382"}',accept("application/json"),content_type("application/json; charset=utf-8"))
BehroozMirmolavi commented 5 years ago

Great thanks a lot i see.