JSONDecodeError with py_translator (google-translate) : how to make the library to work for new translations?












0














I am trying to use Google Translate Api to translate the text contained in a vast kaggle csv that I have converted in dataframe.



I have tried using googletrans which gives this error :



AttributeError: 'NoneType' object has no attribute 'group'


but this seems to be a recurrent error like it was reported here.



I switched to py_translator that also uses Google Translate. It worked fine at first and I could try as stated in the tutorial a simple command like that :



from py_translator import Translator
s = Translator().translate(text='Hello my friend', dest='es').text
print(s)


However after trying to apply it on my dataframe that contains 156 060 rows, because I must have forgotten the API limit of 5K or 15K, it completely stopped working, and I cannot run anymore the code above as it would always raise the same error :



JSONDecodeError: Expecting value: line 1 column 1 (char 0)


the code that I used just before I ran into this error was :



df = pd.DataFrame(index=range(0,len(train)),columns=['translation'])
translator = Translator()
for i, row in enumerate(train['text']):
df.loc[i,'translation'] = translator.translate(row,dest='Fr').text


It ran into an error, but the first rows of the dataframe where correctly translated.
However, since then, I cannot get any result using any functionalities of py_translator, and it may be due to limits as suggested here or here.



1) How is it possible to reuse py_translator translation on simple requests and not run into the same error over and over on code that used to work before?



2) Is there a better library or a better way to translate a big dataset?



Many thanks










share|improve this question



























    0














    I am trying to use Google Translate Api to translate the text contained in a vast kaggle csv that I have converted in dataframe.



    I have tried using googletrans which gives this error :



    AttributeError: 'NoneType' object has no attribute 'group'


    but this seems to be a recurrent error like it was reported here.



    I switched to py_translator that also uses Google Translate. It worked fine at first and I could try as stated in the tutorial a simple command like that :



    from py_translator import Translator
    s = Translator().translate(text='Hello my friend', dest='es').text
    print(s)


    However after trying to apply it on my dataframe that contains 156 060 rows, because I must have forgotten the API limit of 5K or 15K, it completely stopped working, and I cannot run anymore the code above as it would always raise the same error :



    JSONDecodeError: Expecting value: line 1 column 1 (char 0)


    the code that I used just before I ran into this error was :



    df = pd.DataFrame(index=range(0,len(train)),columns=['translation'])
    translator = Translator()
    for i, row in enumerate(train['text']):
    df.loc[i,'translation'] = translator.translate(row,dest='Fr').text


    It ran into an error, but the first rows of the dataframe where correctly translated.
    However, since then, I cannot get any result using any functionalities of py_translator, and it may be due to limits as suggested here or here.



    1) How is it possible to reuse py_translator translation on simple requests and not run into the same error over and over on code that used to work before?



    2) Is there a better library or a better way to translate a big dataset?



    Many thanks










    share|improve this question

























      0












      0








      0


      1





      I am trying to use Google Translate Api to translate the text contained in a vast kaggle csv that I have converted in dataframe.



      I have tried using googletrans which gives this error :



      AttributeError: 'NoneType' object has no attribute 'group'


      but this seems to be a recurrent error like it was reported here.



      I switched to py_translator that also uses Google Translate. It worked fine at first and I could try as stated in the tutorial a simple command like that :



      from py_translator import Translator
      s = Translator().translate(text='Hello my friend', dest='es').text
      print(s)


      However after trying to apply it on my dataframe that contains 156 060 rows, because I must have forgotten the API limit of 5K or 15K, it completely stopped working, and I cannot run anymore the code above as it would always raise the same error :



      JSONDecodeError: Expecting value: line 1 column 1 (char 0)


      the code that I used just before I ran into this error was :



      df = pd.DataFrame(index=range(0,len(train)),columns=['translation'])
      translator = Translator()
      for i, row in enumerate(train['text']):
      df.loc[i,'translation'] = translator.translate(row,dest='Fr').text


      It ran into an error, but the first rows of the dataframe where correctly translated.
      However, since then, I cannot get any result using any functionalities of py_translator, and it may be due to limits as suggested here or here.



      1) How is it possible to reuse py_translator translation on simple requests and not run into the same error over and over on code that used to work before?



      2) Is there a better library or a better way to translate a big dataset?



      Many thanks










      share|improve this question













      I am trying to use Google Translate Api to translate the text contained in a vast kaggle csv that I have converted in dataframe.



      I have tried using googletrans which gives this error :



      AttributeError: 'NoneType' object has no attribute 'group'


      but this seems to be a recurrent error like it was reported here.



      I switched to py_translator that also uses Google Translate. It worked fine at first and I could try as stated in the tutorial a simple command like that :



      from py_translator import Translator
      s = Translator().translate(text='Hello my friend', dest='es').text
      print(s)


      However after trying to apply it on my dataframe that contains 156 060 rows, because I must have forgotten the API limit of 5K or 15K, it completely stopped working, and I cannot run anymore the code above as it would always raise the same error :



      JSONDecodeError: Expecting value: line 1 column 1 (char 0)


      the code that I used just before I ran into this error was :



      df = pd.DataFrame(index=range(0,len(train)),columns=['translation'])
      translator = Translator()
      for i, row in enumerate(train['text']):
      df.loc[i,'translation'] = translator.translate(row,dest='Fr').text


      It ran into an error, but the first rows of the dataframe where correctly translated.
      However, since then, I cannot get any result using any functionalities of py_translator, and it may be due to limits as suggested here or here.



      1) How is it possible to reuse py_translator translation on simple requests and not run into the same error over and over on code that used to work before?



      2) Is there a better library or a better way to translate a big dataset?



      Many thanks







      python pandas google-translate google-translation-api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 21:05









      Louise PLouise P

      166




      166
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382615%2fjsondecodeerror-with-py-translator-google-translate-how-to-make-the-library%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382615%2fjsondecodeerror-with-py-translator-google-translate-how-to-make-the-library%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]