Pyftpsync works only without TLS - python

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.

Related

Python connection with database

I am trying to connect the database mysql to mycode but i don't know what is the problen i have treid many solution but still confuse if any body can help ?
`
e:\hotelManagnment\customer.py:38: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
img2=img2.resize((100,40),Image.ANTIALIAS)
Traceback (most recent call last):
File "e:\hotelManagnment\customer.py", line 262, in <module>
obj=Cust_Win(root)
File "e:\hotelManagnment\customer.py", line 212, in __init__
self.fetch_data()
File "e:\hotelManagnment\customer.py", line 245, in fetch_data
conn=mysql.connector.connect(host="localhost",username="root",password="",database="managment")
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\pooling.py", line 287, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\connection.py", line 137, in __init__
self.connect(**kwargs)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\abstracts.py", line 1108, in connect
self._open_connection()
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\connection.py", line 544, in _open_connection
self.set_converter_class(self._converter_class)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\abstracts.py", line 1284, in set_converter_class
self.converter = convclass(charset_name, self._use_unicode)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\conversion.py", line 136, in __init__
MySQLConverterBase.__init__(self, charset, use_unicode, str_fallback)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\conversion.py", line 59, in __init__
self.set_charset(charset)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\conversion.py", line 73, in set_charset
self.charset_id = CharacterSet.get_charset_info(self.charset)[0]
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\constants.py", line 775, in get_charset_info
info = cls.get_default_collation(charset)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mysql\connector\constants.py", line 746, in get_default_collation
raise ProgrammingError(f"Character set '{charset}' unsupported")
mysql.connector.errors.ProgrammingError: Character set 'utf8' unsupported
`

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

PyMongo - Server timeout on localhost

I'm trying to learn how to work with MongoDB in Python but everytime I run my code it takes so long that I have to kill it and I get these tracebacks.
"/Volumes/ADATA HD720/flapPY/venv/bin/python" "/Volumes/ADATA HD720/flapPY/Database.py"
Traceback (most recent call last):
File "/Volumes/ADATA HD720/flapPY/Database.py", line 8, in <module>
x = high_scores.insert_one(mydict)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 693, in insert_one
session=session),
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 607, in _insert
bypass_doc_val, session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 595, in _insert_one
acknowledged, _insert_command, session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1247, in _retryable_write
with self._tmp_session(session) as s:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1576, in _tmp_session
s = self._ensure_session(session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session
server_session = self._get_server_session()
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session
return self._topology.get_server_session()
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session
None)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/topology.py", line 208, in _select_servers_loop
self._condition.wait(common.MIN_HEARTBEAT_INTERVAL)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 300, in wait
gotit = waiter.acquire(True, timeout)
KeyboardInterrupt
Process finished with exit code 1
This is my code:
import pymongo
client = pymongo.MongoClient("localhost", 27017)
database = client["database"]
high_scores = database["highscore"]
mydict = {"highscore" : 5}
x = high_scores.insert_one(mydict)
print(x.inserted_id)
My belief is that it cannot connect to the localhost
Apparently mongodb was not started on my PC. All I had to do was to run
brew services start mongodb
and it worked perfectly.

Error connecting to PyPy3 multiprocessing remote manager

I am trying to run the remote manager example code from the multiprocessing documentation in pypy3 but I get an error connecting the client.
Traceback (most recent call last):
File "C:/temp/testpypy/mp_client.py", line 7, in <module>
m.connect()
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\managers.py", line 455, in connect
conn = Client(self._address, authkey=self._authkey)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 493, in Client
answer_challenge(c, authkey)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 732, in answer_challenge
message = connection.recv_bytes(256) # reject large message
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 216, in recv_bytes
buf = self._recv_bytes(maxlength)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 407, in _recv_bytes
buf = self._recv(4)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 386, in _recv
buf.write(chunk)
TypeError: 'str' does not support the buffer interface
if I try to connect to it from a CPython interpreter (which is my ultimate goal) I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\managers.py", line 455, in connect
conn = Client(self._address, authkey=self._authkey)
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 493, in Client
answer_challenge(c, authkey)
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 737, in answer_challenge
response = connection.recv_bytes(256) # reject large message
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 218, in recv_bytes
self._bad_message_length()
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 151, in _bad_message_length
raise OSError("bad message length")
OSError: bad message length
Turns out to be a bug in PyPy3.
Here is the fixed ticket:
https://bitbucket.org/pypy/pypy/issues/2841/remote-multprocessing-issue#comment-45861347

Client/Server TLS in Python

I need to create a client/server example with TLS 1.2 in Python. I spent many hours and I did not get anything...
I'm trying this example: https://github.com/titeuf87/python3-tls-example
I'm getting this error when I execute the client.py:
Exception in callback None
handle: <Handle cancelled>
Traceback (most recent call last):
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\events.py", line 125, in _run
self._callback(*self._args)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\selector_events.py", line 667, in _read_ready
self._protocol.data_received(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 486, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 200, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 633, in do_handshake
match_hostname(self.getpeercert(), self.server_hostname)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 300, in match_hostname
% (hostname, dnsnames[0]))
ssl.CertificateError: hostname '127.0.0.1' doesn't match 'server'
Traceback (most recent call last):
File "C:\Users\PC\workspace\testingpython\client.py", line 18, in <module>
loop.run_until_complete(connect())
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\base_events.py", line 342, in run_until_complete
return future.result()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py", line 274, in result
raise self._exception
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\tasks.py", line 237, in _step
result = coro.throw(exc)
File "C:\Users\PC\workspace\testingpython\client.py", line 11, in connect
reader, writer = yield from asyncio.open_connection("127.0.0.1", 1234, ssl=sslcontext)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\streams.py", line 64, in open_connection
lambda: protocol, host, port, **kwds)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\base_events.py", line 669, in create_connection
sock, protocol_factory, ssl, server_hostname)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\base_events.py", line 692, in _create_connection_transport
yield from waiter
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py", line 385, in __iter__
yield self # This tells Task to wait for completion.
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\tasks.py", line 288, in _wakeup
value = future.result()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py", line 274, in result
raise self._exception
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\events.py", line 125, in _run
self._callback(*self._args)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\selector_events.py", line 667, in _read_ready
self._protocol.data_received(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 486, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 200, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 633, in do_handshake
match_hostname(self.getpeercert(), self.server_hostname)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 300, in match_hostname
% (hostname, dnsnames[0]))
ssl.CertificateError: hostname '127.0.0.1' doesn't match 'server'
Does anyone know of any examples?

Categories