Generate a Google Translate API token through the Socks5 proxy using gtoken.py
hongy...@gmail.com
hongyi.zhao at gmail.com
Tue Jul 27 04:55:33 EDT 2021
I want to use [gtoken.py](https://github.com/ssut/py-googletrans/blob/master/googletrans/gtoken.py) through a socks5 proxy. Based on the comment [here](https://github.com/encode/httpx/issues/203#issuecomment-611914974) and the example usage in [gtoken.py](https://github.com/ssut/py-googletrans/blob/d15c94f176463b2ce6199a42a1c517690366977f/googletrans/gtoken.py#L29), I tried with the following method, but failed:
```python
(datasci) werner at X10DAi:~$ ipython
Python 3.9.1 (default, Feb 10 2021, 15:30:33)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.23.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import socks
In [2]: import socket
In [3]: socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 18889)
...: socket.socket = socks.socksocket
In [4]: from googletrans.gtoken import TokenAcquirer
In [5]: acquirer=TokenAcquirer()
In [6]: text = 'test'
In [7]: tk= acquirer.do(text)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-8223ccd9014e> in <module>
----> 1 tk= acquirer.do(text)
~/.pyenv/versions/3.9.1/envs/datasci/lib/python3.9/site-packages/googletrans/gtoken.py in do(self, text)
192
193 def do(self, text):
--> 194 self._update()
195 tk = self.acquire(text)
196 return tk
~/.pyenv/versions/3.9.1/envs/datasci/lib/python3.9/site-packages/googletrans/gtoken.py in _update(self)
60
61 # this will be the same as python code after stripping out a reserved word 'var'
---> 62 code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
63 # unescape special ascii characters such like a \x3d(=)
64 code = code.encode().decode('unicode-escape')
AttributeError: 'NoneType' object has no attribute 'group'
```
Any hints for this problem will be highly appreciated.
Regards,
HY
More information about the Python-list
mailing list