Comments (6)
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.
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.
You should send your code when reporting issues. Anyway, it seems to be a proxy/httpx issue.
from gpytranslate.
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.
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.
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)
- unable to translate some texts HOT 1
- ConnectError exception while using a local proxy HOT 4
- about the proxy HOT 1
- Clients5.google.com is potentially dangerous HOT 1
- [Bug]: We need an empty response handler HOT 13
- JSONDecodeError HOT 7
- [Bug]: Getting 302 Response HOT 3
- [Bug]: TypeError: Response.iter_bytes() got an unexpected keyword argument 'chunk_size' HOT 2
- Library cannot be used in Python 3.6 and 3.7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpytranslate.