Mailing List Archive

Generate a Google Translate API token through the Socks5 proxy using gtoken.py
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
--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
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@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On Wednesday, July 28, 2021 at 7:25:27 AM UTC+8, cameron...@gmail.com wrote:
> Just to follow on a bit to Dennis:

But I can't any reply from Dennis in this issue.

> 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 <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On 27Jul2021 19:24, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>On Wednesday, July 28, 2021 at 7:25:27 AM UTC+8, cameron...@gmail.com wrote:
>> Just to follow on a bit to Dennis:
>
>But I can't any reply from Dennis in this issue.

Odd, because I replied to his reply to you :-)

If you're using a threaded view of the list, his reply should be right
before mine. If you're not, it was about 6 hours before my reply.

Cheers,
Cameron Simpson <cs@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On 28/07/2021 07:32, Cameron Simpson wrote:
> On 27Jul2021 19:24, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>> On Wednesday, July 28, 2021 at 7:25:27 AM UTC+8, cameron...@gmail.com wrote:
>>> Just to follow on a bit to Dennis:
>>
>> But I can't any reply from Dennis in this issue.
>
> Odd, because I replied to his reply to you :-)

Perhaps it has something to do with the X-No-Archive flag set by Dennis?

--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On Wednesday, July 28, 2021 at 3:05:11 PM UTC+8, Peter Otten wrote:
> On 28/07/2021 07:32, Cameron Simpson wrote:
> > On 27Jul2021 19:24, Hongyi Zhao <hongy...@gmail.com> wrote:
> >> On Wednesday, July 28, 2021 at 7:25:27 AM UTC+8, cameron...@gmail.com wrote:
> >>> Just to follow on a bit to Dennis:
> >>
> >> But I can't any reply from Dennis in this issue.
> >
> > Odd, because I replied to his reply to you :-)
> Perhaps it has something to do with the X-No-Archive flag set by Dennis?

I'm not sure. I use the Google Groups from Firefox for reading from/posting on this group.

HY
--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On 28/07/2021 18:40, Dennis Lee Bieber wrote:
> On Wed, 28 Jul 2021 09:04:40 +0200, Peter Otten <__peter__@web.de>
> declaimed the following:
>
>>
>> Perhaps it has something to do with the X-No-Archive flag set by Dennis?
>
> According to my properties page in Agent, I've turned that off except
> if the message I'm replying to has it set.

I'm yet to see an archived post by you -- maybe that setting is
overridden somewhere.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On Thu, 29 Jul 2021 15:45:26 +0200, Peter Otten <__peter__@web.de>
declaimed the following:

>On 28/07/2021 18:40, Dennis Lee Bieber wrote:
>> On Wed, 28 Jul 2021 09:04:40 +0200, Peter Otten <__peter__@web.de>
>> declaimed the following:
>>
>>>
>>> Perhaps it has something to do with the X-No-Archive flag set by Dennis?
>>
>> According to my properties page in Agent, I've turned that off except
>> if the message I'm replying to has it set.
>
>I'm yet to see an archived post by you -- maybe that setting is
>overridden somewhere.

And naturally, once I found the legacy (per persona) custom setting, I
failed to edit the main persona. Hopefully this time it's set...

Appears Agent added the per "folder" and "default'
[x] X-no-Archive
flags in some later release, and those are what I've been tweaking...

But looking at the INI file, I found there were persona specific custom
settings for "additional header fields", Which I likely set up back in the
days of Agent 5 or so, currently on Agent 8



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

--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On 29/07/2021 17:43, Dennis Lee Bieber wrote:
> On Thu, 29 Jul 2021 15:45:26 +0200, Peter Otten <__peter__@web.de>
> declaimed the following:
>
>> On 28/07/2021 18:40, Dennis Lee Bieber wrote:
>>> On Wed, 28 Jul 2021 09:04:40 +0200, Peter Otten <__peter__@web.de>
>>> declaimed the following:
>>>
>>>>
>>>> Perhaps it has something to do with the X-No-Archive flag set by Dennis?
>>>
>>> According to my properties page in Agent, I've turned that off except
>>> if the message I'm replying to has it set.
>>
>> I'm yet to see an archived post by you -- maybe that setting is
>> overridden somewhere.
>
> And naturally, once I found the legacy (per persona) custom setting, I
> failed to edit the main persona. Hopefully this time it's set...

https://mail.python.org/pipermail/python-list/2021-July/902975.html

You are now officially archived ;)

--
https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py [ In reply to ]
On Fri, 30 Jul 2021 13:17:50 +0200, Peter Otten <__peter__@web.de>
declaimed the following:

>
>https://mail.python.org/pipermail/python-list/2021-July/902975.html
>
>You are now officially archived ;)

Pity the choice was the boolean "X-No-Archive"... Consensus
implementation of an "X-Expire-After: <days>" would have been friendlier
(Google Groups USED to expire X-No-Archive posts after a week, instead of
the current practice of: post says no-archive, delete immediately).


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

--
https://mail.python.org/mailman/listinfo/python-list