Python 3.2 SSLError - python

I am working on a simple script that calls Instagram API.
Error -
File "C:\Python32\lib\ssl.py", line 168, in wrap_socket
_context=self)
File "C:\Python32\lib\ssl.py", line 255, in __init__
raise x
File "C:\Python32\lib\ssl.py", line 251, in __init__
self.do_handshake()
File "C:\Python32\lib\ssl.py", line 430, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 8] _ssl.c:392: EOF occurred in violation of protocol

Related

error [SSL: CERTIFICATE_VERIFY_FAILED] when running 'earthengine authenticate'

I am trying to authorize access to Earth Engine via earthengine authenticate but get the following error:
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1010, in _send_output
self.send(msg)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 950, in send
self.connect()
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1424, in connect
self.sock = self._context.wrap_socket(self.sock,
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\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:1124)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\Scripts\earthengine-script.py", line 9, in <module>
sys.exit(main())
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\eecli.py", line 84, in main
_run_command()
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\eecli.py", line 63, in _run_command
dispatcher.run(args, config)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\commands.py", line 353, in run
self.command_dict[vars(args)[self.dest]].run(args, config)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\commands.py", line 386, in run
ee.Authenticate(**args_auth)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\__init__.py", line 86, in Authenticate
oauth.authenticate(authorization_code, quiet, code_verifier)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\oauth.py", line 233, in authenticate
_obtain_and_write_token(None, code_verifier) # Will prompt for auth_code.
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\oauth.py", line 139, in _obtain_and_write_token
token = request_token(auth_code.strip(), code_verifier)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\oauth.py", line 82, in request_token
response = request.urlopen(
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 1393, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 1353, 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:1124)>
Otherwise I have access to Earth Engine.
I am running this in a new conda environment with Python 3.8.1.
Running it with Python 3.6.1 results in a similar error ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852).
And running this on a different maschine does not result in errors.
Do you have any ideas?

Python - [SSL: DH_KEY_TOO_SMALL] dh key too small

I have python script which uses FTP_TLS to get access to FTPS server. When I try to do_handshake next error appears:
File "/usr/local/lib/python3.7/ftplib.py", line 749, in login
self.auth()
File "/usr/local/lib/python3.7/ftplib.py", line 761, in auth
server_hostname=host)
File "/usr/local/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/usr/local/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/usr/local/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1076)
My script:
ftp = FTP_TLS()
ftp.connect(host, port)
ftp.login(user, passwd)
ftp.prot_p()
Is there any way to turn off this warning or change some ciphers?

kafka-python SASL/SCRAM-SHA-256 auth

I need to connect to Kafka broker in python using SASL/SCRAM-SHA-256 authentication.
I use the kafka-python (2.0.1) python library which allows this kind of connection/authentication.
This is an example of code, but i get the error ... not Brokers available
prod = KafkaProducer(bootstrap_servers='server:9093',
security_protocol='SASL_SSL',
ssl_certfile='path to ca in pem format',
sasl_mechanism='SCRAM-SHA-256',
sasl_plain_username='xxx',
sasl_plain_password='xxx')
Getting the following error
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:897)
20-04-06 09:58:52 - root - 1 - 140658864072256 - MainThread - ERROR - Error in connection to kafka
Traceback (most recent call last):
File "/*****/*****/dao/kafka_dao.py", line 44, in __init__
**self.consumer_additional_params)
File "/opt/app-root/lib/python3.6/site-packages/kafka/consumer/group.py", line 355, in __init__
self._client = KafkaClient(metrics=self._metrics, **self.config)
File "/opt/app-root/lib/python3.6/site-packages/kafka/client_async.py", line 242, in __init__
self.config['api_version'] = self.check_version(timeout=check_timeout)
File "/opt/app-root/lib/python3.6/site-packages/kafka/client_async.py", line 907, in check_version
version = conn.check_version(timeout=remaining, strict=strict, topics=list(self.config['bootstrap_topics_filter']))
File "/opt/app-root/lib/python3.6/site-packages/kafka/conn.py", line 1228, in check_version
if not self.connect_blocking(timeout_at - time.time()):
File "/opt/app-root/lib/python3.6/site-packages/kafka/conn.py", line 337, in connect_blocking
self.connect()
File "/opt/app-root/lib/python3.6/site-packages/kafka/conn.py", line 426, in connect
if self._try_handshake():
File "/opt/app-root/lib/python3.6/site-packages/kafka/conn.py", line 505, in _try_handshake
self._sock.do_handshake()
File "/usr/lib64/python3.6/ssl.py", line 1033, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib64/python3.6/ssl.py", line 645, in do_handshake
self._sslobj.do_handshake()
Where am I doing wrong??

Not able to use Imdbpy. Getting an ssl exception

I am trying to use IMDbPy but I am getting an SSL error. I am new to imdbpy and python so not sure if I am doing anything wrong. Any help would be greatly appreciated.
from imdb import IMDb
ia = IMDb(accessSystem='html')
dp = ia.get_movie('1431045')
print(dp.keys())
Here is the stacktrace:
2018-04-17 20:20:49,830 CRITICAL [imdbpy] /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/imdb/_exceptions.py:32: IMDbDataAccessError exception raised; args: ({'errcode': 'socket error', 'errmsg': '[Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)', 'original exception': OSError('socket error', OSError('socket error', SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)'))), 'proxy': '', 'url': 'http://www.imdb.com/title/tt1431045/reference', 'exception type': 'IOError'},); kwds: {}
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1693, in open
return getattr(self, name)(url)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1903, in open_https
return self._open_generic_http(self._https_connection, url, data)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1852, in _open_generic_http
http_conn.request("GET", selector, headers=headers)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1261, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 385, in wrap_socket
_context=self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 760, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 996, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 641, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)

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