Android Question POST request -Endpoint does not exist

Argonc

Member
Licensed User
Longtime User
Hello,
I have been trying in vain to break up the POST request for several hours. Do you have any idea what I'm wrong?

Python (works, I just changed the key)
Python:
url = "https://google-translate1.p.rapidapi.com/language/translate/v2"

payload = "source=cs&q=Dobr%C3%BD%20den!&target=en"
headers = {
    'x-rapidapi-host': "google-translate1.p.rapidapi.com",
    'x-rapidapi-key': "0f2ff54355msh60ff6bcb8a67568p195f88jsn849412bdec67",
    'accept-encoding': "application/gzip",
    'content-type': "application/x-www-form-urlencoded"
    }

response = requests.request("POST", url, data=payload, headers=headers)


B4A:
HttpJop:
    Dim j As HttpJob

    j.Initialize("", Me) 'name is empty as it is no longer needed
    j.download2("https://google-translate1.p.rapidapi.com/language/translate/v2", Array As String("data","source=cs&q=Dobr%C3%BD%20den!&target=en"))   
    j.GetRequest.SetHeader("x-rapidapi-key","0f2ff54355msh60ff6bcb8a67568p195f88jsn849412bdec67")
    j.GetRequest.SetHeader("x-rapidapi-host","google-translate1.p.rapidapi.com")
    j.GetRequest.SetHeader("accept-encoding", "application/gzip")
    j.GetRequest.SetHeader("content-type", "application/x-www-form-urlencoded")


ResponseError. Reason: Not Found, Response: {"message":"Endpoint\/language\/translate\/v2 does not exist"}
 

drgottjr

Expert
Licensed User
Longtime User
1) you shouldn't show your key. we here at b4x are - of course - totally trustworthy, but forum posts appear on google. i realize there would be no way for us to test your code without a key, but it's a mistake.
2) if you need to call a POST, why are you calling a GET? (j.download2 is a GET, not a POST).
3) if haven't sifted through your parameters, but #1 and #2 jumped to mind immediately.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
brief followup: i tried your code (with your key), and i also tried after changing the GET to POSTstring.
1) the endpoint does exist
2) i got the same error in both cases: that i wasn't subscribed to the api. nothing about non-existent endpoint.

not sure where that leaves you.


i noticed this in rapidapi.com's documention for google's translate api:
B4X:
req.headers({
    "content-type": "application/x-www-form-urlencoded",
    "accept-encoding": "application/gzip",
    "x-rapidapi-key": "SIGN-UP-FOR-KEY",
    "x-rapidapi-host": "google-translate1.p.rapidapi.com",
    "useQueryString": true
});

you version of the request headers seems to be missing "useQueryString". see what that does.


so, i decided to try with my rapidapi key. i subscribed to google's translate api, got an acknowledgment from rapidapi that i had subscribed, and
tried again. this time:
ResponseError. Reason: Bad Gateway, Response: {"messages":"The API is unreachable, please contact the API provider", "info": "Your Client (working) ---> Gateway (working) ---> API (not working)}.
even testing with rapidapi's test page derived no response. sorry
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Try:

POST
B4X:
j.PostString("https://google-translate1.p.rapidapi.com/language/translate/v2", "source=cs&q=Dobr%C3%BD%20den!&target=en")

GET
B4X:
j.Download2("https://google-translate1.p.rapidapi.com/language/translate/v2", Array As String("source", "cs", "q", "Dobrý den!", "target", "en"))
 
Upvote 0

Argonc

Member
Licensed User
Longtime User
Try:

POST
B4X:
j.PostString("https://google-translate1.p.rapidapi.com/language/translate/v2", "source=cs&q=Dobr%C3%BD%20den!&target=en")

GET
B4X:
j.Download2("https://google-translate1.p.rapidapi.com/language/translate/v2", Array As String("source", "cs", "q", "Dobrý den!", "target", "en"))

It works, thank you very much! We actually called GET instead of POST.
 
Upvote 0

Argonc

Member
Licensed User
Longtime User
[QUOTE = "drgottjr, příspěvek: 794713, člen: 31245"]
krátké sledování: zkusil jsem váš kód (s vaším klíčem) a také jsem se pokusil po změně GET na POSTstring.
1) koncový bod existuje
2) Dostal jsem stejnou chybu v obou případech: že jsem nebyl přihlášen k odběru API. nic o neexistujícím koncovém bodě.

nejste si jisti, kde vás to nechá.


Všiml jsem si to v dokumentaci rapidapi.com pro Google API pro překlad:
[CODE = b4x]
záhlaví požadavku ({
"content-type": "application / x-www-form-urlencoded",
"accept-encoding": "application / gzip",
"x-rapidapi-key": "PŘIHLÁSIT SE NA KLÍČ",
"x-rapidapi-host": "google-translate1.p.rapidapi.com",
"useQueryString": true
});
[/KÓD]

Zdá se, že ve vaší hlavičce požadavku chybí „useQueryString“. podívejte se, co to dělá.


tak jsem se rozhodl to zkusit s mým klíčem rapidapi. Přihlásil jsem se k odběru překladu API Google, dostal jsem potvrzení od RapidApi, že jsem se přihlásil k odběru, a
zkusil to znovu. tentokrát:
Chyba odpovědi. Důvod: Bad Gateway, Response: {"messages": "API je nedosažitelné, kontaktujte poskytovatele API", "info": "Váš klient (funkční) ---> Gateway (funkční) ---> API (ne pracovní)}.
dokonce ani testování pomocí testovací stránky rapidapi neodvozovalo žádnou odpověď. Promiňte
[/CITÁT]
It already works for me, thank you very much! I actually called GET instead of POST. The key I gave here is made up with the right one to work for you.
 
Upvote 0
Top