Can't establish a connection using snowflake-connector-python v1.9 - python

(Asking the following question on behalf of a client)
............
Due to the size of all dependencies snowflake-connector-python is having I had to switch to v1.9 (106Mb total size) and now I'm not able to establish connection, v2.0 is not functioning as well. The only working version is v2.0.1 but it's huge (320Mb total size) comparing to the v1.9.
Traceback (most recent call last):
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1131, in validate_by_direct_connection
self.process_ocsp_response(issuer, cert_id, ocsp_response)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_asn1crypto.py", line 280, in process_ocsp_response
tbs_response_data)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_asn1crypto.py", line 316, in verify_signature
pubkey = cert.public_key.unwrap().dump()
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/asn1crypto/keys.py", line 1065, in unwrap
'asn1crypto.keys.PublicKeyInfo().unwrap() has been removed, '
asn1crypto._errors.APIException: asn1crypto.keys.PublicKeyInfo().unwrap() has been removed, please use oscrypto.asymmetric.PublicKey().unwrap() instead
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 790, in _request_exec
auth=SnowflakeAuth(token),
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/adapters.py", line 370, in send
timeout=timeout
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
self._validate_conn(conn)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
conn.connect()
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connection.py", line 238, in connect
ssl_version=resolved_ssl_version)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ssl_wrap_socket.py", line 395, in ssl_wrap_socket_with_ocsp
).validate(server_hostname, ret.connection)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 996, in validate
return self._validate(hostname, cert_data, telemetry_data, do_retry, no_exception)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1002, in _validate
cert_data, telemetry_data, hostname, do_retry=do_retry)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1184, in _validate_certificates_sequential
issuer, subject, telemetry_data, hostname, do_retry=do_retry)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1153, in validate_by_direct_connection
err = self.verify_fail_open(ex, telemetry_data)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/ocsp_snowflake.py", line 1166, in verify_fail_open
if ex_obj.errno is ER_SERVER_CERTIFICATE_REVOKED:
AttributeError: 'APIException' object has no attribute 'errno'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 640, in _request_exec_wrapper
**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 883, in _request_exec
raise RetryRequest(err)
snowflake.connector.network.RetryRequest: 'APIException' object has no attribute 'errno'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/avinogradov/git/crux/step_function/snowflake_update/test.py", line 25, in <module>
schema=SCHEMA
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/__init__.py", line 33, in Connect
return SnowflakeConnection(**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 187, in __init__
self.connect(**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 484, in connect
self.__open_connection()
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 700, in __open_connection
self.__authenticate(auth_instance)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/connection.py", line 931, in __authenticate
session_parameters=self._session_parameters,
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/auth.py", line 197, in authenticate
socket_timeout=self._rest._connection.login_timeout)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 521, in _post_request
_include_retry_params=_include_retry_params)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 600, in fetch
**kwargs)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 683, in _request_exec_wrapper
conn, full_url, cause)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/network.py", line 713, in handle_invalid_certificate_error
u'errno': ER_FAILED_TO_REQUEST,
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/errors.py", line 100, in errorhandler_wrapper
connection.errorhandler(connection, cursor, errorclass, errorvalue)
File "/Users/avinogradov/.local/share/virtualenvs/snowflake_update-WVrmvZbT/lib/python3.7/site-packages/snowflake/connector/errors.py", line 73, in default_errorhandler
done_format_msg=errorvalue.get(u'done_format_msg'))
snowflake.connector.errors.OperationalError: 250003: Failed to execute request: 'APIException' object has no attribute 'errno'
............
The client is currently able to get around the issue by using the latest version (2.0.1) but to delete pyarrow and numpy (pip uninstall pyarrow numpy) later to reduce dependencies size (these dependencies are used by customers who are on the Private Preview only).
Are there any better recommendations out there?

You are correct that this is an issue that was fixed in v2.0.1. The older versions of the Python connector are failing while validating the certificate using the recently upgraded package of asn1crypto 1.0.0. The workaround is to use asn1crypt 0.24.0.
pip install snowflake-connector-python asn1crypto==0.24.0

Related

Duplicity is giving a TypeError when uploading to Google Cloud Storage

I have a backup script that has been working fine. I recently updated my OS (to Ubuntu 19.10) and tried to install all of the dependencies but I'm getting an error.
My script is something like:
export PASSPHRASE="passphrase"
PATH=$PATH:/home/jeremy/.boto
export HOME='/home/jeremy/'
DATE=`date +%Y-%m-%d:%H:%M:%S`
echo "Running backup at $DATE" >> /home/jeremy/.backup/log
duplicity --full-if-older-than 1M \
--archive-dir /home/jeremy/.cache/duplicity/ \
/home/jeremy \
gs://x1_carbon_backup >> /home/jeremy/.backup/log
I created the .boto file with gsutil and I can use gsutil successfully, so authentication appears to be working.
The traceback looks like an encoding/decoding problem but I can't tell if it's a problem with how I'm doing things or a bug in boto or duplicity
Traceback (innermost last):
File "/usr/bin/duplicity", line 107, in <module>
with_tempdir(main)
File "/usr/bin/duplicity", line 93, in with_tempdir
fn()
File "/usr/lib/python3/dist-packages/duplicity/dup_main.py", line 1522, in main
action = commandline.ProcessCommandLine(sys.argv[1:])
File "/usr/lib/python3/dist-packages/duplicity/commandline.py", line 1200, in ProcessCommandLine
globals.backend = backend.get_backend(args[0])
File "/usr/lib/python3/dist-packages/duplicity/backend.py", line 225, in get_backend
obj = get_backend_object(url_string)
File "/usr/lib/python3/dist-packages/duplicity/backend.py", line 211, in get_backend_object
return factory(pu)
File "/usr/lib/python3/dist-packages/duplicity/backends/_boto_single.py", line 173, in __init__
self.resetConnection()
File "/usr/lib/python3/dist-packages/duplicity/backends/_boto_single.py", line 199, in resetConnection
location=self.my_location)
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/gs/connection.py", line 95, in create_bucket
data=get_utf8_value(data))
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/s3/connection.py", line 659, in make_request
auth_path = self.calling_format.build_auth_path(bucket, key)
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/s3/connection.py", line 94, in build_auth_path
path = '/' + bucket
TypeError: can only concatenate str (not "bytes") to str
I tried to decode the bucket variable as suggested here.
Now I am getting an SSLCertVerificationError, below:
Traceback (most recent call last):
File "/usr/bin/duplicity", line 163, in <module>
if u"Forced assertion for testing" in util.uexc(e):
File "/usr/lib/python3/dist-packages/duplicity/util.py", line 120, in uexc
return fsdecode(m)
File "/usr/lib/python3.7/os.py", line 822, in fsdecode
filename = fspath(filename) # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not int
Backup complete. Checking for old backups to remove
Traceback (most recent call last):
File "/usr/bin/duplicity", line 107, in <module>
with_tempdir(main)
File "/usr/bin/duplicity", line 93, in with_tempdir
fn()
File "/usr/lib/python3/dist-packages/duplicity/dup_main.py", line 1522, in main
action = commandline.ProcessCommandLine(sys.argv[1:])
File "/usr/lib/python3/dist-packages/duplicity/commandline.py", line 1200, in ProcessCommandLine
globals.backend = backend.get_backend(args[0])
File "/usr/lib/python3/dist-packages/duplicity/backend.py", line 225, in get_backend
obj = get_backend_object(url_string)
File "/usr/lib/python3/dist-packages/duplicity/backend.py", line 211, in get_backend_object
return factory(pu)
File "/usr/lib/python3/dist-packages/duplicity/backends/_boto_single.py", line 173, in __init__
self.resetConnection()
File "/usr/lib/python3/dist-packages/duplicity/backends/_boto_single.py", line 199, in resetConnection
location=self.my_location)
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/gs/connection.py", line 95, in create_bucket
data=get_utf8_value(data))
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/s3/connection.py", line 671, in make_request
retry_handler=retry_handler
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/connection.py", line 1071, in make_request
retry_handler=retry_handler)
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/connection.py", line 1030, in _mexe
raise ex
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/connection.py", line 943, in _mexe
request.body, request.headers)
File "/usr/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/lib/python3.7/http/client.py", line 966, in send
self.connect()
File "/home/jeremy/.local/lib/python3.7/site-packages/boto/https_connection.py", line 131, in connect
ca_certs=self.ca_certs)
File "/usr/lib/python3.7/ssl.py", line 1238, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs
File "/usr/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/usr/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/usr/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1076)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/duplicity", line 163, in <module>
if u"Forced assertion for testing" in util.uexc(e):
File "/usr/lib/python3/dist-packages/duplicity/util.py", line 120, in uexc
return fsdecode(m)
File "/usr/lib/python3.7/os.py", line 822, in fsdecode
filename = fspath(filename) # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not int

error handling for network disconnect error

I am using pyowm to get weather update after each minutes. If I disconnect my internet or low internet what error will be occure and how can i handle this error.For try..except method..what possible exception have to use...??
my code is....
import tkinter as tk
from tkinter import *
import pyowm
from PIL import ImageTk, Image
win=tk.Tk()
#frame_for_showing_weather.
weather_frame=Frame(win,bg='black',width='300',height='300')
weather_frame.place(x=0,y=0)
weath=Label(weather_frame,font=('Agency',100),fg='white',bg='black')
weath.place(x=10,y=10)
temp1=''
owm=pyowm.OWM('my api key')
def obs():
global temp1
observation = owm.weather_at_place('Barisal,BD')
w=observation.get_weather()
temp2=w.get_temperature('celsius')
if(temp2!=temp1):
temp1=temp2['temp']
weath.config(text=str(int(temp1))+chr(176))
print('Alhamdulillah,Yeah that is worked')
weath.after(60000,obs)
obs()
win.mainloop()
please someone explain...I am new at python.
if i drop my connection this big error occure...
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "C:\Program Files (x86)\Python35-32\lib\http\client.py", line 1197, in getresponse
response.begin()
File "C:\Program Files (x86)\Python35-32\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "C:\Program Files (x86)\Python35-32\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Program Files (x86)\Python35-32\lib\socket.py", line 575, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\adapters.py", line 445, in send
timeout=timeout
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\util\retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
raise value
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "C:\Program Files (x86)\Python35-32\lib\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: HTTPConnectionPool(host='api.openweathermap.org', port=80): Read timed out. (read timeout=2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\commons\http_client.py", line 24, in get_json
timeout=self.timeout, verify=self.verify_ssl_certs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\adapters.py", line 526, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='api.openweathermap.org', port=80): Read timed out. (read timeout=2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "C:\Program Files (x86)\Python35-32\lib\tkinter\__init__.py", line 596, in callit
func(*args)
File "C:\Users\James Bond\Desktop\test.py", line 23, in obs
observation = owm.weather_at_place('Barisal,BD')
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\webapi25\owm25.py", line 210, in weather_at_place
_, json_data = self._wapi.cacheable_get_json(uri, params=params)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\commons\http_client.py", line 44, in cacheable_get_json
status_code, data = self.get_json(uri, params=params, headers=headers)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\commons\http_client.py", line 30, in get_json
raise api_call_error.APICallTimeoutError('API call timeouted')
pyowm.exceptions.api_call_error.APICallTimeoutError: Exception in calling OWM web API.
Reason: API call timeouted
Caused by: None
how can i handle this error...?

Pyftpsync works only without TLS

Hi I'm using pyftpsync in order to upload new images (downloaded every day) in a online store skipping the existing ones.
From the author site I'm using this code (with my personal data of course):
from ftpsync.targets import FsTarget
from ftpsync.ftp_target import FtpTarget
from ftpsync.synchronizers import UploadSynchronizer
local = FsTarget("~/temp")
user ="joe"
passwd = "secret"
remote = FtpTarget("/temp", "example.com", username=user, password=passwd)
opts= {"force": False, "delete_unmatched": True, "verbose": 3, "dry_run" : False}
s = UploadSynchronizer(local, remote, opts,tls=True)
s.run()
This work for me correctly only if I delete the tls option, otherwise I obtain this error while connecting to my server:
Traceback (most recent call last):
File "sync.py", line 25, in <module>
s.run()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/synchronizers.py", line 139, in run
res = self._sync_dir()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/synchronizers.py", line 416, in _sync_dir
remote_entries = self.remote.get_dir()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 310, in get_dir
self.ftp.retrlines("MLSD", _addline)
File "/usr/lib/python3.4/ftplib.py", line 466, in retrlines
resp = self.sendcmd('TYPE A')
File "/usr/lib/python3.4/ftplib.py", line 272, in sendcmd
return self.getresp()
File "/usr/lib/python3.4/ftplib.py", line 235, in getresp
resp = self.getmultiline()
File "/usr/lib/python3.4/ftplib.py", line 221, in getmultiline
line = self.getline()
File "/usr/lib/python3.4/ftplib.py", line 209, in getline
raise EOFError
EOFError
Could not remove lock file: Underlying socket connection gone (_ssl.c:1570)
Exception ignored in: <bound method FtpTarget.__del__ of <ftpsync.ftp_target.FtpTarget object at 0x7fe397ae7710>>
Traceback (most recent call last):
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/targets.py", line 70, in __del__
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 153, in close
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 187, in _unlock
File "/usr/lib/python3.4/ftplib.py", line 613, in delete
File "/usr/lib/python3.4/ftplib.py", line 271, in sendcmd
File "/usr/lib/python3.4/ftplib.py", line 198, in putcmd
File "/usr/lib/python3.4/ftplib.py", line 193, in putline
File "/usr/lib/python3.4/ssl.py", line 720, in sendall
File "/usr/lib/python3.4/ssl.py", line 681, in send
ssl.SSLError: Underlying socket connection gone (_ssl.c:1570)
It's obviously a problem related to the encryption, but I don't know how to fix it.

SSL exception while converting to *.exe with cx_freeze

After converting of my program to EXE with cx_freeze I get the following error:
Traceback (most recent call last):
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 292, in s
sl_wrap_socket
context.load_verify_locations(ca_certs, ca_cert_dir)
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\adapters.py", line 376, in send
timeout=timeout
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559,
in urlopen
body=body, headers=headers)
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345,
in _make_request
self._validate_conn(conn)
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 784,
in _validate_conn
conn.connect()
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connection.py", line 252, in
connect
ssl_version=resolved_ssl_version)
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 294, in s
sl_wrap_socket
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "genderator.py", line 109, in <module>
File "genderator.py", line 62, in checkLimits
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\genderize\__init__.py", line 88, in get
params=params)
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "C:\Users\tyszkap\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 2] No such file or directory
Even though I don't use requests library explicitely I assume that Genderize does. So I have read a couple of posts about it and tried to pass the path to my cacert.pem file but it still doesn't solve my issue. This is how I formatted my setup.py file:
from cx_Freeze import setup, Executable
import requests.certs
import sys
executable = Executable( script = "genderator.py" )
# Add certificate to the build
options = {
"build_exe": {
'include_files' : [(requests.certs.where(), 'cacert.pem')]
}
}
setup(
version = "0",
requires = ["requests"],
options = options,
executables = [executable])
I use Python 3.4.4 on Windows 7 64bit. Any idea what I am doing wrong?
You can try adding your certificate as an environment variable as described here and here.
os.environ["REQUESTS_CA_BUNDLE"] = os.path("/path/to/cacert.pem")
But what you've tried should work too.

Problems using PRAW (searching and posting)

I am trying to write a small program with PRAW the python library for Reddit API, and I am searching and posting to reddit greek content.
For example I have the following function:
def find_if_posted(usr, title, url):
for content in usr.search(title):
return True
for content in usr.search(url):
return True
return False
which tries to search if there is a post with the same title or url. usr is the reddit PRAW object. When it starts to search with the url I am getting the error:
Traceback (most recent call last):
File "C:\Users\hargikas\Dropbox\Private\src\reddit\auto_poster\leftist.py", line 133, in <module>
while (key is None) or find_if_posted(usr, key, content[key]):
File "C:\Users\hargikas\Dropbox\Private\src\reddit\auto_poster\leftist.py", line 86, in find_if_posted
for content in usr.search(url):
File "C:\Python34\lib\site-packages\praw\__init__.py", line 1108, in search
**kwargs):
File "C:\Python34\lib\site-packages\praw\__init__.py", line 515, in get_content
root = page_data.get(root_field, page_data)
AttributeError: 'str' object has no attribute 'get'
Also when I am trying to post something (using the submit function) I get this error:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 372, in _make_request
httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 374, in _make_request
httplib_response = conn.getresponse()
File "C:\Python34\lib\http\client.py", line 1162, in getresponse
raise ResponseNotReady(self.__state)
http.client.ResponseNotReady: Request-sent
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
timeout=timeout
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 597, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\retry.py", line 245, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\packages\six.py", line 309, in reraise
raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 374, in _make_request
httplib_response = conn.getresponse()
File "C:\Python34\lib\http\client.py", line 1162, in getresponse
raise ResponseNotReady(self.__state)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ResponseNotReady('Request-sent',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hargikas\Dropbox\Private\src\reddit\auto_poster\leftist.py", line 140, in <module>
usr.submit('greekreddit' , key, url=content[key])
File "C:\Python34\lib\site-packages\praw\decorators.py", line 338, in wrapped
return function(cls, *args, **kwargs)
File "C:\Python34\lib\site-packages\praw\decorators.py", line 237, in wrapped
return function(obj, *args, **kwargs)
File "C:\Python34\lib\site-packages\praw\__init__.py", line 2218, in submit
retry_on_error=False)
File "C:\Python34\lib\site-packages\praw\decorators.py", line 163, in wrapped
return_value = function(reddit_session, *args, **kwargs)
File "C:\Python34\lib\site-packages\praw\__init__.py", line 561, in request_json
retry_on_error=retry_on_error)
File "C:\Python34\lib\site-packages\praw\__init__.py", line 402, in _request
response = handle_redirect()
File "C:\Python34\lib\site-packages\praw\__init__.py", line 375, in handle_redirect
timeout=timeout, **kwargs)
File "C:\Python34\lib\site-packages\praw\handlers.py", line 144, in wrapped
result = function(cls, **kwargs)
File "C:\Python34\lib\site-packages\praw\handlers.py", line 54, in wrapped
return function(cls, **kwargs)
File "C:\Python34\lib\site-packages\praw\handlers.py", line 99, in request
allow_redirects=False)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "C:\Python34\lib\site-packages\requests\adapters.py", line 415, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ResponseNotReady('Request-sent',))
When I am searching using parameters of imgur.com or other "English" sites, I get no error. But when I use it over Greek sites, or posting Greek content I get the above errors.
Do you have an idea what I am doing wrong? I am a newbie with PRAW so any comment is appreciated. I am using Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 and PRAW Version: 2.1.21
Thank you in advance!
Harry

Categories