Generate a Google Translate API token through the Socks5 proxy using gtoken.py

Cameron Simpson cs at cskk.id.au
Tue Jul 27 19:07:58 EDT 2021


Just to follow on a bit to Dennis:

    C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs>python
    googletrans_test.py
    Traceback (most recent call last):
      File "googletrans_test.py", line 4, in <module>
        tk = acquirer.do(text)
      File "C:\Python38\lib\site-packages\googletrans\gtoken.py", line 194, in do
        self._update()
      File "C:\Python38\lib\site-packages\googletrans\gtoken.py", line 62, in _update
        code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
    AttributeError: 'NoneType' object has no attribute 'group'

The implication here is that:

    self.RE_TKK.search(r.text).group(1)

generates the error because:

    self.RE_TKK.search(r.text)

returned None instead of a regular expression match object. That means 
that "r.text" way not what was expected.

Like Dennis, i note the remark "for internal use only", suggesting this 
was some internal Google code for doing something fiddly. It may not be 
the best thing for what you're trying to do.

WRT to a socks proxy, Dennis showed that the issue occurs even without a 
proxy. I would advocate doing all your debugging without trying to use 
socks, then get to going through a socks proxy _after_ the main stuff is 
working.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list