B4J Question [jServer] Too Many Requests

Blueforcer

Well-Known Member
Licensed User
Longtime User
Ive often errors in my Server Handler, but dont know how to fix it:
ResponseError. Reason: Too Many Requests, Response:

This is my code

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim v As String =req.GetParameter("Version")     
    newClient(req.GetParameter("IP"),resp,v)
    StartMessageLoop
End Sub

Sub newClient(adress As String,resp As ServletResponse,version As String)
    Dim job  As HttpJob
    job.Initialize("loc",Me)
    job.Download("http://ip-api.com/json/" & adress.Trim)
    Wait For (job) JobDone(job As HttpJob)
    If job.Success Then
        Dim parser As JSONParser
        parser.Initialize(job.GetString)
        Dim root As Map = parser.NextObject
        Dim status As String = root.Get("status")
        If status =  "success" Then
            analyticClass.activeClients.Put(adress,CreateMap("timestamp":DateTime.Now,"version":version))
        End If
    Else
        logger.write("could not fetch address for " & adress)
    End If
    resp.Write("")
    job.Release
    StopMessageLoop
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
How many calls does your app do on
job.Download("http://ip-api.com/json/" & adress.Trim) Wait For (job) JobDone(job As HttpJob)
in a one minute timespan?

How many requests can I do?
Our endpoints are limited to 45 HTTP requests per minute from an IP address. If you go over this limit your requests will be throttled (HTTP 429) until your rate limit window is reset.
If you need unlimited queries, please see our pro service.

Also note that you are not allowed to use the free api in a commercial project.
 
Last edited:
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
I think the error doesnt come from this API call. Too Many Requests comes from jServer because there is no job.errormessage output. Whether the api access works or not is not that important for now.

It's not a commercial project
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Too Many Requests comes from jServer because there is no job.errormessage output
the job is successful. job.ErrorMessage is not supposed to have any Value in this case.

The output from the apicall is Too Many Requests probably

How many calls does your app do on the Api in a one minute timespan?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Where is the output of your Server from which you are saying it comes from the jserver?
I´m pretty sure jServer can handle a lot of Requests.
Could be more
If they are more than 45 within a 1 minute timespan then the api request will end in an 429 error.
Do NOT use such a amount of requests to prevent the problem.
Alternatively get a License from them and you can call their api unlimited times.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
I'm not sure you understand me.
Where in my code is a log() line where this error message is catched and displayed?
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Well... Thought actually my last question was expressed understandably.
Please just forget the API for one minute. Where is the logoutput happen??
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Please just forget the API for one minute
still, I would put a log(job.GetString) in the success just to completely rule it out. Like DonManfred, this was the very first thing I could think of. It may return success (as in no error), but somewhere in the returned json it may mention something that can help.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
There should be a log(s) directory where the .jar file is located. Check the access logs there and see if you see an error message
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Also, what platform are you running this on? If on Linux, check the nohup.out (or whatever file the output is redirected too).
 
Upvote 0
Top