I have a rest call realized by fuel library in my Android app Kotlin project. While attempting to call httpGet I get this
Caused by: com.github.kittinunf.fuel.core.BubbleFuelError: null com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:84) 03-06 11:32:39.112 6328-6328/com.example.demo I/System.out: com.github.kittinunf.fuel.core.requests.RequestTask.executeRequest(RequestTask.kt:24) com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:44) com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:14) com.github.kittinunf.fuel.core.DeserializableKt.response(Deserializable.kt:166) com.github.kittinunf.fuel.core.requests.DefaultRequest.responseObject(DefaultRequest.kt:463)
Most probably the response seem null, and it fails during deserialization?
What can I do there?
You're calling .responseObject. I think calling .responseBytes or similar should work.
Same here when using in coroutine:
val (request, response, result) = Fuel
.get("https://www.googleapis.com/youtube/v3/videos", listOf(
"key" to BuildConfig.YOUTUBE_DATA_API_KEY,
"part" to "snippet,contentDetails,statistics",
"id" to "US3VTVDRbjE,Ayeg2vlnbUo"
))
.awaitVideosResponseResult(scope = viewModelJob)
I also get the same error when using :
var jsonArray = Fuel.get("http://name.pythonanywhere.com/api/v1/prog").header(Headers.COOKIE, cookie).responseJson().third.get().array()
but it's funny that the code works when I use:
Fuel.get("http://name.pythonanywhere.com/api/v1/prog").header(Headers.COOKIE, cookie).responseJson { request: Request, response: Response, result: Result<FuelJson, FuelError> ->
//incident_count = (count_occurrences('{', response.body().toString()) - 1).toString()
for (i in 0..result.get().array().length() -1){
myReportLat = result.get().array().getJSONObject(i)["latitude"].toString()
myReportLong= result.get().array().getJSONObject(i)["longitude"].toString()
}
Of which now with the later segment I won't be able to access the values of longitude and latitude outside the Fuel block
I can't figure out why this is not working for me:
val (_,_,result )= Fuel.get(requestUrl).responseString()
And this works fine:
requestUrl.httpGet().responseString { _, _, result ->
when (result) {
is Result.Success -> {
// do something on success
}
is Result.Failure -> {
// do something on fail
}
}
}
I would like to work as in the first example, because I would like to return this result.
I have the same errors as those mentioned above with the responseObject method. Blocking queries seem unusable.
Assuming that you guys are running on Android, it sounds to me that, you all might be running into NetworkOnMainThreadException?
Can you try to see result.error.exception is NetworkOnMainThreadException? @baillyjamy @BVADY @KiteCapital ?
@sokarcreative For your case, since you are using the coroutine extension. NetworkOnMainThreadException should not apply to you.
Can you share me with your runnable snippet so I can try on my end?
PS.
I am running this on brand new Android project and it works perfectly.
private suspend fun execute() {
val githubIssue = "https://api.github.com/repos/kittinunf/Fuel/issues/1".httpGet()
.awaitObject(Issue.Deserializer())
println(issue)
}
Output
I/System.out: Issue(id=84908363, title=create readme file, url=https://api.github.com/repos/kittinunf/fuel/issues/1)
I would like to know these information to reproduce
1) Android Version
2) Fuel Version
3) URL address
I would like to hear back on this? We also released new version https://github.com/kittinunf/fuel/releases/tag/2.1.0, do you think it should help solve or at the very least investigate what's going on?
Hello,
Effectively, it was an error of inattention, my synchronous request was in the android main thread. A beginner's mistake. I should have answered faster to avoid wasting your time. I'm sorry.
Anyway, thank you for the modification, I just reproduced this problem and the error is clearer. I think you can close this issue. Sorry again.
Most helpful comment
I can't figure out why this is not working for me:
val (_,_,result )= Fuel.get(requestUrl).responseString()And this works fine:
I would like to work as in the first example, because I would like to return this result.