I keep getting "AttributeError: 'NoneType' object has no attribute 'group' " error even after changing gtoken on googletrans stopped working with error 'NoneType' object has no attribute 'group' but I got __init__() got an unexpected keyword argument 'client'
error instead
here my main.py
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
import uvicorn
from googletrans import Translator
#init
app = FastAPI(debug=True)
templates = Jinja2Templates(directory="template")
#route
@app.get('/')
def home(request: Request):
text = request.get('text')
lang = request.get('lang')
#print('text:',text,'lang:',lang)
#connect the translator
translator=Translator()
#detect langguage
dt = translator.detect(text)
dt2 =dt.lang
#translate the text
translated = translator.translate(text, lang)
tr =translated.text
return templates.TemplateResponse({"request": request},"translates.html",{'translated':tr,'u_lang':dt2,'t_lang':lang})
#def translator(request):
if __name__=="__main__":
uvicorn.run(app,host="127.0.0.1",port=8000)
and here where my translate.html execute the translate within site
<form action="" method="get">
<br>
<div class="form-input">
<center><label for="TextareaInput">Enter Text </label></center>
<center><textarea class="form-control" value="text" id="TextareaInput" rows="3"></textarea></center>
</div>
<div class="ui divider"></div>
<div class="form-selection">
<center><label for="languages">Choose Langguage:</label></center>
<center><select name="trans" id="languages">
<option value="en">English</option>
<option value="ms">Malay</option>
<option value="zh-cn">Mandarin</option>
<option value="ko">Korean</option>
<option value="ja">Japanese</option>
<option value="vi">Vietnamese</option>
<option value="th">Thailand</option>
</select></center>
</div>
<div class="ui divider"></div>
<div>
<center> <button class="ui button">Translate</button></center>
</div>
<div class="ui divider"></div>
<div class="form-output">
<div class="container">
<br><br>
<h1>Text succes translated {{u_lang}} to {{t_lang}}</h1>
<center>
<h1>{{translated}}</h1>
</center>
</div>
</div>
</form>
I already hit wall because this error keep popping
A new alpha version with a fix was released a few minutes ago.
Install the alpha version like this:
pip install googletrans==3.1.0a0
Important thing to note: You have to specify a service url, otherwise the same error still occurs. So this should work:
from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')
But his still returns the error (at least for me):
translator = Translator()
translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')
See the discussion here for details and updates: https://github.com/ssut/py-googletrans/pull/237
See also this discussion: googletrans stopped working with error 'NoneType' object has no attribute 'group'