sloria / TextBlob

Simple, Pythonic, text processing--Sentiment analysis, part-of-speech tagging, noun phrase extraction, translation, and more.
https://textblob.readthedocs.io/
MIT License
9.09k stars 1.13k forks source link

Language Detection Not Working (HTTP Error 503: Service Unavailable) #137

Closed manurajhada closed 7 years ago

manurajhada commented 8 years ago

from textblob import TextBlob txt = u"Test Language Detection" b = TextBlob(txt) b.detect_language()

It is giving "HTTPError: HTTP Error 503: Service Unavailable"

Python Version: 2.7.6 TextBlob Version: 0.11.1 OS: Ubuntu 14.04 LTS & CentOS 6.8

ghost commented 8 years ago

from textblob import TextBlob text = '''Please Miss Fried, He don't mean to be mean , He just needs to leave, He hopes he does not ''' blob = TextBlob(text) blob.translate(to="es")

It shows: HTTPError: Service Unavailable

Erza commented 8 years ago

Same issue on Python 3 with a simple translate, it always throws error 503, since approximately 2 days. It has worked just fine before.

import discord
from discord.ext import commands
from .utils.chat_formatting import *
from .utils import checks
from textblob import TextBlob
import re

class Translate:
    """Translates text to desired language."""

    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def translate(self, *, text : str):
        """Translates text to desired language."""
        pattern = re.compile("\-([a-z]{1,3})")
        m = pattern.match(text)

        if m:
            blob = TextBlob(text.split(' ', 1)[1])
            await self.bot.say("```" + str(blob.translate(to=str(m.group()[1:]))) + "```")
        else:
            blob = TextBlob(text)
            await self.bot.say("```" + str(blob.translate(to="en")) + "```")
manurajhada commented 8 years ago

@Sickness-chan "since approximately 2 days. It has worked just fine before." Same for me.

mcamachoruiz commented 8 years ago

Same here. It seems that google translation uses a token (called tk) generated in javascript to avoid bypasses in its calls. I saw that there is a function in translate.py (_calculate_tk) that calculates it. I guess that that function should be updated, but I still didn't figure out how. I hope that this points someone in the right direction.

manurajhada commented 8 years ago

Any update on this?

gcucurull commented 8 years ago

I'm experiencing this same problem since 4 or 5 days ago.

manurajhada commented 8 years ago

Somehow fixed it. Not sure its a solution or workaround :D I just started fighting with it and made few changes in translate.py (/python/dist-packages/textblob/)

Change List (PFA translate.py.txt):

Tested with Python 2.7.6, Ubuntu 14.04, TextBlob 0.11.1

Here is the Updated Code File: translate.py.txt

Test Code:

from textblob import TextBlob
txt = u"मेरा नाम एलेक्स है"
#txt = "my name is alex"
b = TextBlob(txt)
print b.detect_language()
print b.translate(to='en')

Note: Changes made in existing code file is just to share a workable solution to the reported issue. It is shared by and as an individual; not from the owner or community.

sloria commented 8 years ago

@manurajhada Would you be so kind as to send a PR with your fix?

manurajhada commented 8 years ago

Its working for small text only, for large paragraph google response is "Your client has issued a malformed or illegal request."

AdrianLC commented 8 years ago

Porting the code to requests cannot be very significant to the fix as requests uses urllib itself.

They must have changed something to the tk parameter that we might never have gotten right, in the first place. We got it from another project but it's reverse engineered from minified javascript.

The repo for gTTS-token hasn't been updated since June so it won't be enough, assuming they indeed changed the code. Let's hope that someone can understand the new algorithm.

valmikadik commented 8 years ago

Any update on this issue ? Getting the same while using textblob. It was working fine until 2-3 days back. Any idea how to fix this ???

valmikadik commented 8 years ago

Seems like all the modules which internally uses the Google Translation APIs are having the same problem. I have tried goslate and same error.

andrediaslopes commented 8 years ago

Yep, same problem here.. I've also tried other modules and they are all replying error 503 :-\

jschnurr commented 8 years ago

I've submitted PR #139, which works for me most of the time, but I still get some 503's. Let me know if it works for you.

ysolis commented 8 years ago

Affects me too, I learn traducing first to english (from spanish) now the learn databases are corrupted because the latest thing learned come from text in spanish, not traduced. I deploy my app and install TextBlob egg from pypi

WisdomWolf commented 7 years ago

It seems that this is still broken. I was getting this error in HangoutsBot, so I setup a virtualenv to test TextBlob specifically and I'm seeing the same 503 error. :(

scne commented 7 years ago

up!

diegoesteves commented 7 years ago

any API that uses Google as service will get 503! it's the same for others such as Goslate. It turns out that now you have to pay (https://cloud.google.com/translate/v2/pricing). Once they get your IP, it's done 👎

jabbalaci commented 7 years ago

Same issue here. I switched to https://github.com/Mimino666/langdetect , which seems to work.

sloria commented 7 years ago

This has been fixed in #148 . I will cut a release shortly.