Python3 selenoid can't ignore SSL certificate verification - python

I'm trying to control selenoid from another network computer.
Make drivers with this
self.drivers.append(webdriver.Remote(
command_executor='http://e2f5a65c53.ngrok.io/wd/hub', desired_capabilities=capabilities))
when I run this code getting this error
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connection.py", line 464, in connect
_match_hostname(cert, self.assert_hostname or server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connection.py", line 512, in _match_hostname
match_hostname(cert, asserted_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 416, in match_hostname
raise CertificateError("hostname %r "
ssl.SSLCertVerificationError: ("hostname '3.22.30.40' doesn't match either of '*.ngrok.io', 'ngrok.io'",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/ryo/Dropbox/Mac/Desktop/selenium_for_beWinning/autoTradeGUI.py", line 4, in <module>
trading = Trading()
File "/Users/ryo/Dropbox/Mac/Desktop/selenium_for_beWinning/main.py", line 32, in __init__
self.driver.append(webdriver.Remote(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/remote_connection.py", line 402, in _request
resp = http.request(method, url, body=body, headers=headers)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/request.py", line 78, in request
return self.request_encode_body(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/request.py", line 170, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/poolmanager.py", line 417, in urlopen
return self.urlopen(method, redirect_location, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/poolmanager.py", line 375, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 783, in urlopen
return self.urlopen(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 783, in urlopen
return self.urlopen(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='3.22.30.40', port=443): Max retries exceeded with url: /wd/hub/session (Caused by SSLError(SSLCertVerificationError("hostname '3.22.30.40' doesn't match either of '*.ngrok.io', 'ngrok.io'")))
Then I tried to ignore SSL certificate verification.
ssl._create_default_https_context = ssl._create_unverified_context
by this line of code
but still getting the same error
How can I solve this problem?

Try to add acceptInsecureCerts = true capability. This will not work when your web site has strict transport security (HSTS) enabled.

Related

Hey guys i was trying read csv file using pandas in pycharm i am getting this error how to resolve it ,i was able to run in googlecolab but in pycharm [duplicate]

This question already has answers here:
SSL: CERTIFICATE_VERIFY_FAILED error when loading data into seaborn?
(3 answers)
Closed 9 months ago.
#i am getting url error how do i resolve it
C:\Python\python.exe E:/data_science/Python_basic/module1_eda/EDA.py
Traceback (most recent call last):
File "C:\Python\lib\urllib\request.py", line 1350, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Python\lib\http\client.py", line 1277, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Python\lib\http\client.py", line 1323, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Python\lib\http\client.py", line 1272, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Python\lib\http\client.py", line 1032, in _send_output
self.send(msg)
File "C:\Python\lib\http\client.py", line 972, in send
self.connect()
File "C:\Python\lib\http\client.py", line 1447, in connect
server_hostname=server_hostname)
File "C:\Python\lib\ssl.py", line 423, in wrap_socket
session=session
File "C:\Python\lib\ssl.py", line 870, in _create
self.do_handshake()
File "C:\Python\lib\ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:/data_science/Python_basic/module1_eda/EDA.py", line 9, in <module>
adult = pd.read_csv(data_url,names=column_headers)
File "C:\Python\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "C:\Python\lib\site-packages\pandas\io\parsers\readers.py", line 586, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:\Python\lib\site-packages\pandas\io\parsers\readers.py", line 482, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Python\lib\site-packages\pandas\io\parsers\readers.py", line 811, in __init__
self._engine = self._make_engine(self.engine)
File "C:\Python\lib\site-packages\pandas\io\parsers\readers.py", line 1040, in _make_engine
return mapping[engine](self.f, **self.options) # type: ignore[call-arg]
File "C:\Python\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 51, in __init__
self._open_handles(src, kwds)
File "C:\Python\lib\site-packages\pandas\io\parsers\base_parser.py", line 229, in _open_handles
errors=kwds.get("encoding_errors", "strict"),
File "C:\Python\lib\site-packages\pandas\io\common.py", line 614, in get_handle
storage_options=storage_options,
File "C:\Python\lib\site-packages\pandas\io\common.py", line 312, in _get_filepath_or_buffer
with urlopen(req_info) as req:
File "C:\Python\lib\site-packages\pandas\io\common.py", line 212, in urlopen
return urllib.request.urlopen(*args, **kwargs)
File "C:\Python\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Python\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Python\lib\urllib\request.py", line 543, in _open
'_open', req)
File "C:\Python\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Python\lib\urllib\request.py", line 1393, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Python\lib\urllib\request.py", line 1352, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)>
Process finished with exit code 1
Seems like you're trying to download the datafile from some URL and because of self-signed certificate you're getting this error. You can simply disable SSL verification during fetching.
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Cannot read file with PyCharm

I'm trying to upload example from dash documentation.
When I try (with PyCharm)
df = pd.read_csv(
'https://raw.githubusercontent.com/plotly/datasets/master/solar.csv'
)
I get these errors.
But when I try the same code with Anaconda Jupyter it works fine. It means problem is not in my OS but in PyCharm.
Can you advise what should I do?
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1342, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1010, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 950, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1424, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/main.py", line 4, in <module>
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/util/_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 680, in read_csv
return _read(filepath_or_buffer, kwds)
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 575, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 933, in __init__
self._engine = self._make_engine(f, self.engine)
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/io/parsers/readers.py", line 1217, in _make_engine
self.handles = get_handle( # type: ignore[call-overload]
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/io/common.py", line 670, in get_handle
ioargs = _get_filepath_or_buffer(
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/io/common.py", line 339, in _get_filepath_or_buffer
with urlopen(req_info) as req:
File "/Users/zaurguliyev/Documents/PyTraining/PyCharm/test/sales_analysis/venv/lib/python3.9/site-packages/pandas/io/common.py", line 239, in urlopen
return urllib.request.urlopen(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 517, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 534, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1385, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1345, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>
Process finished with exit code 1
I think you should check whether you're using the same Python interpreter and Pandas version in both Jupyter and PyCharm.
Find Jupyter interpreter: How to know which Python is running in Jupyter notebook?
(Check this if using Spyder: https://docs.spyder-ide.org/current/faq.html#using-existing-environment)
Check if it's the same in PyCharm: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#interpreter

Slack unable to connect to send an message

I am using python slack module to send a message to a slack channel and i have also installed all the required modules (slack, slackClient, openssl) as well but I am facing with SLL violation. I am not sure if it is related to proxy or not. Any help would be appreciated.
code:
import slack
import ssl
SLACK_API_TOKEN = "xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client = slack.WebClient(token=SLACK_API_TOKEN)
response = client.chat_postMessage(
channel='#channelName',
text="testing")
if (response["ok"]):
print("Notification sent to Slack")
Error:
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1346, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1285, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1331, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1280, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1040, in _send_output
self.send(msg)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 980, in send
self.connect()
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1454, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1129)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/sai/Downloads/Gen3/POC_TEST.py", line 19, in <module>
response = client.chat_postMessage(
File "/usr/local/lib/python3.9/site-packages/slack_sdk/web/legacy_client.py", line 2091, in chat_postMessage
return self.api_call("chat.postMessage", json=kwargs)
File "/usr/local/lib/python3.9/site-packages/slack_sdk/web/legacy_base_client.py", line 167, in api_call
return self._sync_send(api_url=api_url, req_args=req_args)
File "/usr/local/lib/python3.9/site-packages/slack_sdk/web/legacy_base_client.py", line 258, in _sync_send
return self._urllib_api_call(
File "/usr/local/lib/python3.9/site-packages/slack_sdk/web/legacy_base_client.py", line 370, in _urllib_api_call
response = self._perform_urllib_http_request(url=url, args=request_args)
File "/usr/local/lib/python3.9/site-packages/slack_sdk/web/legacy_base_client.py", line 535, in _perform_urllib_http_request
raise err
File "/usr/local/lib/python3.9/site-packages/slack_sdk/web/legacy_base_client.py", line 496, in _perform_urllib_http_request
resp = opener.open(req, timeout=self.timeout) # skipcq: BAN-B310
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 517, in open
response = self._open(req, data)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 534, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
result = func(*args)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1389, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1349, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:1129)>
Thanks

104, Connection reset by peer. When sending multiple long http post requests

I have a kubernetes cluster (on GKE) which runs tornado.web.Application server, that calls heavy dask.distributed calculations on that cluster.
Now I want to test my server, and send it multiple requests at once, to see if it handles those requests as it should.
When I'm sending only one request, it does everything and behaves as expected, no matter how big the request is.
But when I send more than one request, after like 5 minutes (I also tried on server side just to sleep, without making any calculations and got the same results), I get the following:
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 1354, in getresponse
response.begin()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/home/michael/anaconda3/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py", line 531, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/michael/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 1354, in getresponse
response.begin()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/home/michael/anaconda3/lib/python3.7/http/client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/home/michael/anaconda3/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/michael/anaconda3/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "<ipython-input-4-ce4ad22684d3>", line 24, in fire
response = requests.post(url, data=payload, headers=headers, timeout=3600)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/michael/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
And none of the requests returns.
How can I get the behaviour I need, without these errors?
I need a server that can handle many requests, and to test it from my computer.

why the translation api of python version demo api timeout when invoked

# Imports the Google Cloud client library
from google.cloud import translate
# Instantiates a client
translate_client = translate.Client()
# The text to translate
text = u'Hello, world!'
# The target language
target = 'ru'
# Translates some text into Russian
translation = translate_client.translate(
text,
target_language=target)
print(u'Text: {}'.format(text))
print(u'Translation: {}'.format(translation['translatedText']))
I use google translation api of python version demo,and find that the method translate_client.translate allways throws timeout excption ,what is wrong with this?timeout when the method called.
Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
conn.connect()
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connection.py", line 344, in connect
ssl_context=context)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\util\ssl_.py", line 344, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\util\retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
conn.connect()
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\connection.py", line 344, in connect
ssl_context=context)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\urllib3\util\ssl_.py", line 344, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(0, 'Error'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled5/translatetest.py", line 15, in
print(u'Text: {}'.format(text))
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\google\cloud\translate_v2\client.py", line 233, in translate
method='POST', path='', data=data)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\google\cloud_http.py", line 290, in api_request
headers=headers, target_object=_target_object)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\google\cloud_http.py", line 183, in _make_request
return self._do_request(method, url, headers, data, target_object)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\google\cloud_http.py", line 212, in _do_request
url=url, method=method, headers=headers, data=data)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\google\auth\transport\requests.py", line 201, in request
method, url, data=data, headers=request_headers, **kwargs)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Administrator\PycharmProjects\untitled5\venv\lib\site-packages\requests\adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

Categories