Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

My little brother got this fortune: nohup rm -fr /& So he did...


devel / comp.lang.python / Generate a Google Translate API token through the Socks5 proxy using gtoken.py

SubjectAuthor
* Generate a Google Translate API token through the Socks5 proxy using gtoken.pyhongy...@gmail.com
`- Re: Generate a Google Translate API token through the Socks5 proxyDennis Lee Bieber

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

<611ba3b7-4f01-4cd0-8d02-d81e1e3aa4b4n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14305&group=comp.lang.python#14305

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:620a:62d:: with SMTP id 13mr20808490qkv.18.1627376133491;
Tue, 27 Jul 2021 01:55:33 -0700 (PDT)
X-Received: by 2002:a05:6214:300c:: with SMTP id ke12mr21462080qvb.38.1627376133334;
Tue, 27 Jul 2021 01:55:33 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Tue, 27 Jul 2021 01:55:33 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.76.156; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.76.156
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <611ba3b7-4f01-4cd0-8d02-d81e1e3aa4b4n@googlegroups.com>
Subject: Generate a Google Translate API token through the Socks5 proxy using gtoken.py
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 27 Jul 2021 08:55:33 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: hongy...@gmail.com - Tue, 27 Jul 2021 08:55 UTC

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@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

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

<mailman.269.1627407734.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14319&group=comp.lang.python#14319

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: Generate a Google Translate API token through the Socks5 proxy
using gtoken.py
Date: Tue, 27 Jul 2021 13:09:15 -0400
Organization: IISS Elusive Unicorn
Lines: 74
Message-ID: <mailman.269.1627407734.4164.python-list@python.org>
References: <611ba3b7-4f01-4cd0-8d02-d81e1e3aa4b4n@googlegroups.com>
<ice0gg1u870huloqsce15d8igs02sbtb81@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de CRUSbtX9bXVXZFF9ErWErwehfQtjFkbznUWGQAMRjxfw==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'jul': 0.04; 'traceback':
0.04; '(most': 0.05; 'class,': 0.05; 'last):': 0.05; '"""': 0.09;
'along,': 0.09; 'received:ciao.gmane.io': 0.09;
'received:gmane.io': 0.09; 'received:list': 0.09; 'requests.':
0.09; 'subject:API': 0.09; 'looks': 0.11; 'import': 0.14;
'"test"': 0.16; 'api.': 0.16; 'confusing': 0.16; 'email
addr:gmail.com"': 0.16; 'hint': 0.16; 'message-id:@4ax.com': 0.16;
'page...': 0.16; 'received:116.202': 0.16; 'received:116.202.254':
0.16; 'received:116.202.254.214': 0.16; 'uninstall': 0.16;
'url:latest': 0.16; 'tue,': 0.18; 'uses': 0.19; 'object': 0.23;
'to:addr:python-list': 0.23; 'subject:using': 0.24; 'code': 0.24;
'seems': 0.26; 'error': 0.28; 'text': 0.29; 'header:User-Agent:1':
0.31; 'header:Organization:1': 0.31; 'but': 0.31; "i'm": 0.32;
'starts': 0.32; 'class': 0.33; 'skip:" 20': 0.33; 'url-
ip:104.17/16': 0.35; 'trying': 0.36; 'file': 0.38; 'though': 0.38;
'use': 0.38; 'include': 0.40; 'example': 0.40; 'package': 0.40;
'valid': 0.40; 'touch': 0.60; 'internal': 0.63; 'pay': 0.64;
'per': 0.64; 'your': 0.64; 'subject:Google': 0.65; 'skip:t 20':
0.67; 'mix': 0.69; 'subject:through': 0.69; 'received:116': 0.71;
'2021': 0.84; 'attribute': 0.84; 'carries': 0.84; 'irrelevant,':
0.84; 'url-ip:76/8': 0.84; 'google,': 0.93
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: ForteAgent/8.00.32.1272
X-No-Archive: YES
X-Mailman-Approved-At: Tue, 27 Jul 2021 13:42:13 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <ice0gg1u870huloqsce15d8igs02sbtb81@4ax.com>
X-Mailman-Original-References: <611ba3b7-4f01-4cd0-8d02-d81e1e3aa4b4n@googlegroups.com>
 by: Dennis Lee Bieber - Tue, 27 Jul 2021 17:09 UTC

On Tue, 27 Jul 2021 01:55:33 -0700 (PDT), "hongy...@gmail.com"
<hongyi.zhao@gmail.com> declaimed the following:

>In [4]: from googletrans.gtoken import TokenAcquirer
>
Per documentation: https://py-googletrans.readthedocs.io/en/latest/

"""
googletrans.gtoken

Hint

This is for internal use only to generate a valid token to access
translate.google.com ajax API.

class googletrans.gtoken.TokenAcquirer(client: httpx._client.Client,
tkk='0', host='translate.google.com')
"""

I'm not sure how to interpret the definition shown -- it starts out as
a class, but then seems to include a mix of superclass and initialization
arguments).

Also a touch confusing -- should this be "...you do NOT have this..."
"""
translate.google.com uses a token to authorize the requests. If you are not
Google, you do have this token and will have to pay for use.
"""

>In [5]: acquirer=TokenAcquirer()
>
>In [6]: text = 'test'
>
>In [7]: tk= acquirer.do(text)

Though it looks much like you are trying the example shown in that
linked page...

Your mention of socks/etc. is irrelevant, as just the pure
"""
from googletrans.gtoken import TokenAcquirer
acquirer = TokenAcquirer()
text = "test"
tk = acquirer.do(text)
"""
results in the error
"""
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'

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs>
"""

(now to uninstall all the crud that package carries along, since I have no
need for it).

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor