Giter Club home page Giter Club logo

Comments (6)

DavideGalilei avatar DavideGalilei commented on May 30, 2024

You need to remove curly brackets from ip address. Refer to https://www.python-httpx.org/compatibility/#proxy-keys.

Correct usage should be t = SyncTranslator(proxies={"https://": "https://222.37.211.42:46603"})

from gpytranslate.

jyhjzx avatar jyhjzx commented on May 30, 2024

https://115.209.51.131:45131

Fifteen thousand factories foul the italian ligurian riviera.

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/http_proxy.py", line 232, in _tunnel_request
    extensions=extensions,
  File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 136, in handle_request
    self.socket = self._open_socket(timeout)
  File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 168, in _open_socket
    local_address=self._local_address,
  File "/usr/local/lib/python3.7/site-packages/httpcore/_backends/sync.py", line 144, in open_tcp_stream
    return SyncSocketStream(sock=sock)
  File "/usr/local/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.7/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc) from None
httpcore.ConnectError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:1045)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 185, in handle_request
    extensions=extensions,
  File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/http_proxy.py", line 128, in handle_request
    method, url, headers=headers, stream=stream, extensions=extensions
  File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/http_proxy.py", line 256, in _tunnel_request
    raise ProxyError(exc)
httpcore.ProxyError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:1045)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "jyh_test.py", line 37, in <module>
    translation = t.translate(tmp, targetlang="zh-CN")
  File "/usr/local/lib/python3.7/site-packages/gpytranslate/sync/sync_translator.py", line 119, in translate
    if isinstance(text, str)
  File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 1121, in post
    timeout=timeout,
  File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 788, in request
    request, auth=auth, allow_redirects=allow_redirects, timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 883, in send
    history=[],
  File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 912, in _send_handling_auth
    history=history,
  File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 947, in _send_handling_redirects
    response = self._send_single_request(request, timeout)
  File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 988, in _send_single_request
    extensions={"timeout": timeout.as_dict()},
  File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 185, in handle_request
    extensions=extensions,
  File "/usr/local/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ProxyError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:1045)

from gpytranslate.

DavideGalilei avatar DavideGalilei commented on May 30, 2024

You should send your code when reporting issues. Anyway, it seems to be a proxy/httpx issue.

from gpytranslate.

jyhjzx avatar jyhjzx commented on May 30, 2024
from gpytranslate import SyncTranslator
import requests
import json

file = open("single_en", "r", encoding="utf-8")

proxies = {"https": "", }
api_url = 'http://t.ipjldl.com/index.php/api/entry?method=proxyServer.generate_api_url&packid=0&fa=0&fetch_key=&groupid=0&qty=1&time=100&pro=&city=&port=1&format=json&ss=5&css=&ipport=1&et=1&dt=1&specialTxt=3&specialJson=&usertype=14'
header = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3970.5 Safari/537.36'}

def get_one_proxies():
    try:
        response = requests.get(api_url, headers=header, timeout=5)
        if response.status_code != 200:
            get_one_proxies()
        else:
            ip = json.loads(str(response.content.decode('utf-8')))
            proxies["https"] = "https://" + ip["data"][0]["IP"]
    except Exception as e:
        print(e)

if __name__ == "__main__":
    get_one_proxies()
    ip = proxies["https"]
    print(ip)#ip like this :https://115.209.51.131:45131
    if ip:
        t = SyncTranslator(proxies={"https://": ip})
        #t1 = SyncTranslator()
        for line in file:
            tmp =line.strip()
            print(tmp)
            translation = t.translate(tmp, targetlang="zh-CN")
            #language = t.detect(translation.text)
            res = translation.text
            con = tmp + "\t" + res
            print(con)

from gpytranslate.

jyhjzx avatar jyhjzx commented on May 30, 2024

If I don’t use the proxy ip, Google will block the ip and I can’t get the content. Very happy you can reply me

from gpytranslate.

alsoGAMER avatar alsoGAMER commented on May 30, 2024

If I don’t use the proxy ip, Google will block the ip and I can’t get the content. Very happy you can reply me

As @DavideGalilei said, it's an issue with your proxy or httpx, we can't do anything to help you, also because we ran our tests and we haven't got any issue so far.

from gpytranslate.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.