0

Issue: upon calling a vue method (via @tap) that uses axios, I get the following error: "Error: Request failed with status code 429"

I use the same method on a website and it works as expected (except the async/await part, which was added from a suggestion - see the comment at the relative part).

The emulator (Pixel 2 API 28) has access to the web.

Info around my app's setup:

@package.json:

  "dependencies": {
    "@nativescript/theme": "^2.2.1",
    "@vue/devtools": "^5.3.3",
    "axios": "^0.19.2",
    "nativescript-socketio": "^3.3.1",
    "nativescript-toasty": "^3.0.0-alpha.2",
    "nativescript-vue": "^2.6.1",
    "nativescript-vue-devtools": "^1.4.0",
    "tns-core-modules": "^6.5.1",
    "vuex": "^3.3.0"
  }

@AndroidManifest.xml:

// Suggestion from stackoverflow: 
// https://stackoverflow.com/questions/55184243/how-to-call-axios-api-call-in-nativescript-application
<application
    android:usesCleartextTraffic="true"

@npm ls --depth=0

├── axios@0.19.2
├── vue@2.6.11
├── vue-axios@2.1.5
├── xmldom@0.3.0
└── xpath@0.0.27

@main.js :

import Vue from 'nativescript-vue'
import App from './components/App'
import VueDevtools from 'nativescript-vue-devtools'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueDevtools, VueAxios, axios)

@App.vue (the Page Module):

// Also tried: import axios from 'axios/dist/axios'; - As suggested from stack overflow:
// https://stackoverflow.com/questions/55184243/how-to-call-axios-api-call-in-nativescript-application
import axios from 'axios';
[...]
methods: {
        // The reason I've made it 'async', was from a suggestion on S.O., that axios might return Error: the 429 error,
        // due to simultaneous calls.
        // https://stackoverflow.com/questions/54254235/axios-request-failed-with-status-code-429-but-it-is-working-with-postman
        fetchit: async function () { 
            let xmls='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\
                                xmlns:web="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL">\
                <soapenv:Header/>\
                <soapenv:Body>\
                  <tns:GetWeatherInformation>\
                    <name:GetCityWeatherByZIP>65215</name:GetCityWeatherByZIP>\
                  </tns:GetWeatherInformation>\
                </soapenv:Body>\
              </soapenv:Envelope>';
            try{
                const result = await axios.get('https://translate.googleapis.com/translate_a/single?client=gtx&sl=el&tl=en&dt=t&q=πέντε')
                        .then(res=>{console.log("Sucess!", res);})
                        .catch(err=>{console.log("Here......................",err);})
                return result;
            }
            catch (error) {
                console.log("Try-Except Error = ", error);
            }
        }
    }

I suspect that for some reason it's not a coding issue, rather lack of permission of the emulator to my app.

Thank you in advance for any help/suggestion!

Lopofsky
  • 518
  • 6
  • 15
  • As the error suggests, you might be hitting the API too many times from the IP and Google is possibly blocking you. – Manoj May 04 '20 at 17:25
  • Thank you for your insight, however I receive the same error no matter the website I'm trying to make the request. Also as I've mentioned If I run the same method in browser, from the same ip, it works. So it can't be that. – Lopofsky May 05 '20 at 14:35
  • I don't think this end point is meant to be used by developer, where did you find it. Did you go through the translation REST API docs? – Manoj May 05 '20 at 19:48
  • It's just for testing. Besides it does work inside the browser. But let's forget google translate, even when I do a get/post on any other website, I still get the same error, even though the html with Vue works perfectly on the browser. All indications show that the emulator has any issue with http(s) calls from the app. – Lopofsky May 07 '20 at 11:25
  • I've created a fiddle (without the async/await part, since the error it's still the same) to show that it works: just type i.e. "ένα" (without the d quotes) at the text field and press enter. It works: https://jsfiddle.net/lopofsky/q7znbd1p/1/ – Lopofsky May 07 '20 at 11:48

1 Answers1

0

It seems that after all most of the replies were correct.

Google seems that it rejects direct URL calls to google translate (via axios at least), from within the apk. In browser it still works, so I believe (not sure though) that this is the cause.

Thank you all for your insights!

Lopofsky
  • 518
  • 6
  • 15