tfds.load() gives ConnectionResetError - python

I am running tensorflow 2.0.0 (python 3.7.4) on a conda virtual environment on Mac. I am trying to get the IMDb dataset through the following command:
import tensorflow_datasets as tfds
tfds.load('imdb_reviews/subwords8k', split=(tfds.Split.TRAIN, tfds.Split.TEST), with_info = True, as_supervised = True)
to which I am getting the following error:
ConnectionError: ('Connection aborted.', ConnectionResetError(54,
'Connection reset by peer'))
I have asked github tensorflow support (here: tensorflow/tensorflow#36561) and they have concluded that the issue is raised by getresponse() method and it's not a TF issue.
They showed a similar stackoverflow error which involved Requests library. It was solved by installing security packages. I have installed security packages for Requests, Tensorflow and Tensorflow-Datasets using these commands:
conda install -c anaconda pyasn1 ndg-httpsclient pyopenssl
conda install -c anaconda "requests[security]"
conda install -c anaconda "tensorflow[security]"
conda install -c anaconda "tensorflow-datasets[security]"
But the issue is persistent.
They recommended contacting the github Requests support, which I did (here: https://github.com/psf/requests/issues/5374) and they concluded that the exception is because of the remote server resetting the connection and they're not sure why since it's not an issue because of Requests. The stacktrace is:
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 672, in urlopen chunked=chunked,
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 421, in _make_request six.raise_from(e, None)
File "", line 3, in raise_from
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 416, in _make_request httplib_response = conn.getresponse()
File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py",
line 1344, in getresponse response.begin()
File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py",
line 306, in begin version, status, reason = self._read_status()
File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py",
line 267, in _read_status line = str(self.fp.readline(_MAXLINE + 1),
"iso-8859-1")
File "/Users/User/anaconda3/envs/tf/lib/python3.7/socket.py", line
589, in readinto return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/adapters.py",
line 449, in send timeout=timeout
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 720, in urlopen method, url, error=e, _pool=self,
_stacktrace=sys.exc_info()[2]
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/util/retry.py",
line 400, in increment raise six.reraise(type(error), error,
_stacktrace)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/packages/six.py",
line 734, in reraise raise value.with_traceback(tb)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 672, in urlopen chunked=chunked,
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 421, in _make_request six.raise_from(e, None)
File "", line 3, in raise_from
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py",
line 416, in _make_request httplib_response = conn.getresponse()
File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py",
line 1344, in getresponse response.begin()
File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py",
line 306, in begin version, status, reason = self._read_status()
File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py",
line 267, in _read_status line = str(self.fp.readline(_MAXLINE + 1),
"iso-8859-1")
File "/Users/User/anaconda3/envs/tf/lib/python3.7/socket.py", line
589, in readinto return self._sock.recv_into(b)
ProtocolError: ('Connection aborted.', ConnectionResetError(54,
'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/User/nlp1.py", line 13, in (train_data, test_data), info
= tfds.load('imdb_reviews/subwords8k', split=(tfds.Split.TRAIN, tfds.Split.TEST), with_info = True, as_supervised = True)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/api_utils.py",
line 52, in disallow_positional_args_dec return fn(*args, **kwargs)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/registered.py",
line 300, in load
dbuilder.download_and_prepare(**download_and_prepare_kwargs)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/api_utils.py",
line 52, in disallow_positional_args_dec return fn(*args, **kwargs)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/dataset_builder.py",
line 287, in download_and_prepare download_config=download_config)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/dataset_builder.py",
line 948, in _download_and_prepare
max_examples_per_split=download_config.max_examples_per_split,
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/dataset_builder.py",
line 804, in _download_and_prepare for split_generator in
self._split_generators(dl_manager):
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/text/imdb.py",
line 129, in _split_generators arch_path =
dl_manager.download(_DOWNLOAD_URL)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/download_manager.py",
line 301, in download return _map_promise(self._download, url_or_urls)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/download_manager.py",
line 395, in _map_promise res = utils.map_nested(_wait_on_promise,
all_promises)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/utils/py_utils.py",
line 143, in map_nested return function(data_struct)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/download_manager.py",
line 379, in _wait_on_promise return p.get()
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py",
line 510, in get return self._target_settled_value(_raise=True)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py",
line 514, in _target_settled_value return
self._target()._settled_value(_raise)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py",
line 224, in _settled_value reraise(type(raise_val), raise_val,
self._traceback)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/six.py",
line 703, in reraise raise value
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py",
line 842, in handle_future_result resolve(future.result())
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/concurrent/futures/_base.py",
line 428, in result return self.__get_result()
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/concurrent/futures/_base.py",
line 384, in __get_result raise self._exception
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/concurrent/futures/thread.py",
line 57, in run result = self.fn(*self.args, **self.kwargs)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/downloader.py",
line 231, in _sync_download response = session.get(url, stream=True)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/sessions.py",
line 546, in get return self.request('GET', url, **kwargs)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/sessions.py",
line 533, in request resp = self.send(prep, **send_kwargs)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/sessions.py",
line 646, in send r = adapter.send(request, **kwargs)
File
"/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/adapters.py",
line 498, in send raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', ConnectionResetError(54,
'Connection reset by peer'))
I am unable to find any support with this issue anywhere.

Related

Ubuntu server and python scrtipt

Good day to all. I am facing a VDS server problem on Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-167-generic x86_64).
import requests
url = 'https://api.csgo3.run/current-state?montaznayaPena=null'
gameId = 3512446
response = requests.get(url)
print(response)
url = 'https://api.csgorun.ru/games/' + str(gameId)
response = requests.get(url)
print(response)
This is a piece of code from a website parser written in Python 3.11.1 (but it works on 3.6+ versions, I checked). The code was written on Windows 10 2H22. The problem is that on Windows and VirtualBox (ParrotOS) everything works and outputs:
<Response [200]> <Response [200]>
, but on VDS server there is an error on the second request:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 852, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 340, in connect
ssl_context=context)
File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 332, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/usr/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 692, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 852, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 340, in connect
ssl_context=context)
File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 332, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/usr/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
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 "hi.py", line 9, in <module>
response = requests.get(url)
File "/usr/lib/python3/dist-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 520, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 630, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))```
I've tried changing the server OS to Debian and later, installing the oldest and newest versions of python. Tested on other machines.
is this about and how can the problem be solved?

An existing connection was forcibly closed by the remote host in discord.py bot

basically I was using discord.py and another modules when I got this error
when I go this requests connection problem how to solve it?
I was using python-aternos library
it uses cloudscraper,requests,urlib
I don't know what to do saw many posts but most of answers where to change the headings but yeah I want another way like to add a new connection I don't know if that possible can anyone tell me?
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in
urlopen
httplib_response = self._make_request(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 386, in
_make_request
self._validate_conn(conn)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\cloudscraper\__init__.py", line 98, in wrap_socket
return self.ssl_context.orig_wrap_socket(*args, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1071, in _create
self.do_handshake()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 787, in
urlopen
retries = retries.increment(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in
urlopen
httplib_response = self._make_request(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 386, in
_make_request
self._validate_conn(conn)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\cloudscraper\__init__.py", line 98, in wrap_socket
return self.ssl_context.orig_wrap_socket(*args, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1071, in _create
self.do_handshake()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Dell\OneDrive\Desktop\Python\aternos_v3\main.py", line 221, in <module>
asyncio.run(main())
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
return future.result()
File "c:\Users\Dell\OneDrive\Desktop\Python\aternos_v3\main.py", line 218, in main
servers = await get_servers()
File "c:\Users\Dell\OneDrive\Desktop\Python\aternos_v3\server_opener.py", line 13, in get_servers
servs = aternos.list_servers()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\python_aternos\atclient.py", line 326, in list_servers
self.refresh_servers(servers)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\python_aternos\atclient.py", line 352, in refresh_servers
srv = AternosServer(servid, self.atconn)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\python_aternos\atserver.py", line 69, in
__init__
self.fetch()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\python_aternos\atserver.py", line 74, in
fetch
servreq = self.atserver_request(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\python_aternos\atserver.py", line 231, in atserver_request
return self.atconn.request_cloudflare(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\python_aternos\atconnect.py", line 250, in request_cloudflare
req = sendreq(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 600, in get
return self.request("GET", url, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\cloudscraper\__init__.py", line 257, in request
self.perform_request(method, url, *args, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\cloudscraper\__init__.py", line 190, in perform_request
return super(CloudScraper, self).request(method, url, *args, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 547, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
read many sits but none of them was useful can anyone help?

Tensorflow urllib.error.URLError: <urlopen error Errno 60 Operation timed out>

Recently, I tried to use the elmo in tensorflow, but I meet some mistakes, if you can help me, I would be really appreciate.
this is my test_code:
import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
import urllib.request
if __name__ == '__main__':
elmo = hub.Module('https://tfhub.dev/google/elmo/3',trainable=True)
x = ["Hi my friend"]
embeddings = elmo(tf.constant(x),signature="default",as_dict=True)["elmo"]
print(embeddings.numpy())
and I run it, an error woudl be reported in my computer.
urllib.error.URLError: <urlopen error [Errno 60] Operation timed out>
I found lots of methods, but still cannot resolve this question, so if you can help me, I would really appreciate.
and there is all error report.
Traceback (most recent call last):
File "/Library/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 "/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 1417, in connect
super().connect()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 921, in connect
self.sock = self._create_connection(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 843, in create_connection
raise err
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 831, in create_connection
sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jinsongyang/PycharmProjects/pythonProject11/elmo_test.py", line 7, in <module>
elmo = hub.Module('https://tfhub.dev/google/elmo/3',trainable=True)
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/module.py", line 157, in __init__
self._spec = as_module_spec(spec)
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/module.py", line 30, in as_module_spec
return load_module_spec(spec)
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/module.py", line 64, in load_module_spec
path = registry.resolver(path)
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/registry.py", line 51, in __call__
return impl(*args, **kwargs)
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/compressed_module_resolver.py", line 67, in __call__
return resolver.atomic_download(handle, download, module_dir,
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/resolver.py", line 418, in atomic_download
download_fn(handle, tmp_dir)
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/compressed_module_resolver.py", line 63, in download
response = self._call_urlopen(request)
File "/Users/jinsongyang/PycharmProjects/pythonProject11/lib/python3.9/site-packages/tensorflow_hub/resolver.py", line 522, in _call_urlopen
return urllib.request.urlopen(request)
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 1389, 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 1349, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 60] Operation timed out>
Which Tensorflow version are you using?
You need to disable Tensorlfow eager execution mode to run this code.
Use below code:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
before the above code and remove .numpy() as .numpy is only supported in eager mode. If you are in graph mode, it will not be supported.

How do you solve a timeout error in a python dropbox upload script?

I'm currently working on a project to do a timelapse with a raspberry pi3 (which works well, capturing the photos ain't a problem).
However, I used another script to upload those photos to a dropbox account and it work all well, until I checked it out today, seeing a timeout error.
Does anyone know how this could solved?
This is the error:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 453, in wrap_socket
cnx.do_handshake()
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1426, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1149, in _raise_ssl_error
raise WantReadError()
OpenSSL.SSL.WantReadError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
conn.connect()
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 344, in connect
ssl_context=context)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/ssl_.py", line 344, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 456, in wrap_socket
raise timeout('select timed out')
socket.timeout: select timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/packages/six.py", line 686, in reraise
raise value
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 346, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 306, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='content.dropboxapi.com', port=443): Read timed out. (read timeout=30)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/time/picture/drop.py", line 16, in <module>
response = db.files_upload(f.read(), dname)
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/base.py", line 2293, in files_upload
f,
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/dropbox.py", line 274, in request
timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/dropbox.py", line 365, in request_json_string_with_retry
timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/dropbox.py", line 449, in request_json_string
timeout=timeout,
File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='content.dropboxapi.com', port=443): Read timed out. (read timeout=30)
>>>
This is how the code to upload on dropbox looks:
import dropbox
from time import sleep
db = dropbox.Dropbox('apikeyplaceholder')
for i in range(4500): ##4500
name = 'image{0:04d}.jpg'
fname = '/home/pi/Desktop/time/picture/'+name.format(i)
dname = '/'+name.format(i)
f = open(fname, 'rb')
response = db.files_upload(f.read(), dname)
print ('uploaded:', response)
sleep(585)
f.close()
NEW ERROR:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 317, in _send_until_done
return self.connection.send(data)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1256, in send
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1151, in _raise_ssl_error
raise WantWriteError()
OpenSSL.SSL.WantWriteError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 936, in _send_output
self.send(message_body)
File "/usr/lib/python3.5/http/client.py", line 908, in send
self.sock.sendall(data)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 328, in sendall
sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 320, in _send_until_done
raise timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 936, in _send_output
self.send(message_body)
File "/usr/lib/python3.5/http/client.py", line 908, in send
self.sock.sendall(data)
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 328, in sendall
sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
File "/home/pi/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 320, in _send_until_done
raise timeout()
urllib3.exceptions.ProtocolError: ('Connection aborted.', timeout())
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/time/bild/drop.py", line 20, in <module>
response = upload(f, dname)
File "/usr/local/lib/python3.5/dist-packages/backoff/_sync.py", line 94, in retry
ret = target(*args, **kwargs)
File "/home/pi/Desktop/time/bild/drop.py", line 11, in upload
return db.files_upload(f.read(), dname)
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/base.py", line 2293, in files_upload
f,
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/dropbox.py", line 274, in request
timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/dropbox.py", line 365, in request_json_string_with_retry
timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/dropbox/dropbox.py", line 449, in request_json_string
timeout=timeout,
File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', timeout())
Before you implement code to handle the timeout you first need to think about how you want to handle it. A common strategy is the following:
Try re-uploading a certain number of times, potentially coupled with exponential backoff (e.g. using this library)
If that fails either skip the current image or abort the process completely.
Depending on your setup, you might want to put the uploading code into a separate thread so that delays during uploads don't interfere with capturing the photos.
A simple example using the backoff library I've linked to above (untested):
from time import sleep
import backoff
import dropbox
import requests
db = dropbox.Dropbox('apikeyplaceholder')
#backoff.on_exception(backoff.expo, requests.exceptions.ReadTimeout)
def upload(f, name):
return db.files_upload(f.read(), dname)
NAME_PATTERN = '/image{0:04d}.jpg'
for i in range(4500):
name = NAME_PATTERN.format(i)
fname = '/home/pi/Desktop/time/picture' + name
with open(fname, 'rb') as f:
response = upload(f, name)
print ('uploaded:', response)
sleep(585)

Strange SSL error when seeding database via command line

I have a file (it's called conversation_template.py) which I use to seed my DynamoDB database, and it worked until very recently.
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table('tablename')
data = {'<data_goes_here>'}
def add_to_table():
table.put_item(Item=data)
add_to_table()
Now, when I run it in my command line, I get this:
Traceback (most recent call last):
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
self._validate_conn(conn)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
conn.connect()
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/connection.py", line 238, in connect
ssl_version=resolved_ssl_version)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/util/ssl_.py", line 279, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:748)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/adapters.py", line 370, in send
timeout=timeout
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 574, in urlopen
raise SSLError(e)
botocore.vendored.requests.packages.urllib3.exceptions.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:748)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "conversation_template.py", line 74, in <module>
add_to_table()
File "conversation_template.py", line 71, in add_to_table
table.put_item(Item=episode)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/boto3/resources/factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/client.py", line 588, in _make_api_call
operation_model, request_dict)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/endpoint.py", line 141, in make_request
return self._send_request(request_dict, operation_model)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/endpoint.py", line 170, in _send_request
success_response, exception):
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/endpoint.py", line 249, in _needs_retry
caught_exception=caught_exception, request_dict=request_dict)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/hooks.py", line 227, in emit
return self._emit(event_name, kwargs)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/hooks.py", line 210, in _emit
response = handler(**kwargs)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/retryhandler.py", line 183, in __call__
if self._checker(attempts, response, caught_exception):
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/retryhandler.py", line 251, in __call__
caught_exception)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/retryhandler.py", line 277, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/retryhandler.py", line 317, in __call__
caught_exception)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/retryhandler.py", line 223, in __call__
attempt_number, caught_exception)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
raise caught_exception
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/endpoint.py", line 204, in _get_response
proxies=self.proxies, timeout=self.timeout)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/Users/user/anaconda/envs/django_pocketcoach/lib/python3.6/site-packages/botocore/vendored/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
botocore.vendored.requests.exceptions.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:748)
I tried to figure out where the error comes from but I couldn’t do it. Even the error messages didn’t get me anywhere.
I get an SSLError; the protocol is unknown. I found that this type of error could be related to me trying to connect to proxy servers but I am not using one and haven’t done so in the past either.
Any ideas on where this error could come from?
What's worked in the end is to exit my current virtual environment and run:
/Applications/Python\ 3.6/Install\ Certificates.command
And then I entered my virtual environment again and ran:
pip install certifi
That fixed it.
I got help from a friend who suspected it could have to do with the certification verification (related to this: urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error ) but it remains unclear why I didn't get a "Certificate Verification Failed" error.

Categories

Resources