Client/Server TLS in Python - 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?

Related

Unable to create ec2 instance using python boto3 in vs code

import boto3
aws_mag_con = boto3.session.Session(aws_access_key_id='xxxxxxxxxxxxxx',aws_secret_access_key='xxxxxxxxxxxxxx')
newec2 = aws_mag_con.client('ec2','us-east-1c',aws_access_key_id='xxxxxxxxxxxxxx',aws_secret_access_key='xxxxxxxxxxx')
conn = newec2.run_instances(InstanceType="t2.micro",MaxCount=1,MinCount=1,ImageId="ami-0e1d30f2c40c4c701")
Tried to create instance by running the above boto3 script. It is failing with below error. Any help on this?
Traceback (most recent call last):
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py", line 72, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\socket.py", line 953, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\httpsession.py", line 403,
in send
urllib_response = conn.urlopen(
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py", line 525, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 770,
in reraise
raise value
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
conn.connect()
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 358, in connect
conn = self._new_conn()
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPSConnection object at 0x000001AEE1E48E80>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\va20054093\Desktop\Stud\Python\.vscode\.vscode\runinstance.py", line 9, in <module>
conn = newec2.run_instances(InstanceType="t2.micro",MaxCount=1,MinCount=1,ImageId="ami-0e1d30f2c40c4c701")
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 391, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 705, in _make_api_call
http, parsed_response = self._make_request(
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 725, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 104, in
make_request
return self._send_request(request_dict, operation_model)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 138, in
_send_request
while self._needs_retry(attempts, operation_model, request_dict,
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 254, in
_needs_retry
responses = self._event_emitter.emit(
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\hooks.py", line 357, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\hooks.py", line 211, in _emit
response = handler(**kwargs)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 183, in __call__
if self._checker(attempts, response, caught_exception):
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 250, in __call__
should_retry = self._should_retry(attempt_number, response,
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 277, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 316, in __call__
checker_response = checker(attempt_number, response,
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 222, in __call__
return self._check_caught_exception(
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\retryhandler.py", line 359, in _check_caught_exceptionexception
raise caught_exception
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 201, in _do_get_response
http_response = self._send(request)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\endpoint.py", line 270, in _send
return self.http_session.send(request)
File "C:\Users\va20054093\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\httpsession.py", line 432, in send
raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://ec2.us-east-1c.amazonaws.com/"
The error says:
Could not connect to the endpoint URL: "https://ec2.us-east-1c.amazonaws.com/"
The region is named us-east-1, while an AZ is named us-east-1c.
The error is in this line:
newec2 = aws_mag_con.client('ec2','us-east-1c',aws_access_key_id='xxxxxxxxxxxxxx',aws_secret_access_key='xxxxxxxxxxx')
Change us-east-1c into us-east-1.

connection error, from python in RCMES vagrant

I am trying to test python in RCMES vagrant, and I am getting connection error. can anyone please help to solve this
(OCW)vagrant#precise64:~/RCMES/test$ python test.py
Traceback (most recent call last):
File "test.py", line 49, in <module>
urllib.urlretrieve(FILE_LEADER + MODEL, MODEL)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/urllib.py", line 98, in urlretrieve
return opener.retrieve(url, filename, reporthook, data)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/urllib.py", line 245, in retrieve
fp = self.open(url, data)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/urllib.py", line 350, in open_http
h.endheaders(data)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/httplib.py", line 1053, in endheaders
self._send_output(message_body)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/httplib.py", line 897, in _send_output
self.send(msg)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/httplib.py", line 859, in send
self.connect()
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/httplib.py", line 836, in connect
self.timeout, self.source_address)
File "/home/vagrant/miniconda2/envs/OCW/lib/python2.7/socket.py", line 575, in create_connection
raise err
IOError: [Errno socket error] [Errno 110] Connection timed out

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

Django An existing connection was forcibly closed by the remote host

I am googling a lot to find the solution. Maybe this is windows or python bug. I am here for getting help. It is creating problem while debuging.
Traceback (most recent call last):
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 258, in send_preamble
self._write(('Server: %s\r\n' % self.server_software).encode('iso-8859-1'))
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write
self._sock.sendall(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
[19/Apr/2019 14:31:19] ERROR [django.server:154] "GET /static/node_modules/metronic-theme-classic/assets/media/logos/favicon.ico HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52183)
Traceback (most recent call last):
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 258, in send_preamble
self._write(('Server: %s\r\n' % self.server_software).encode('iso-8859-1'))
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write
self._sock.sendall(b)
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\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 116, in handle_error
super().handle_error()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__
self.handle()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 171, in handle
self.handle_one_request()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request
handler.run(self.server.get_app())
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 111, in close
super().close()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
Traceback (most recent call last):
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 333, in send_headers
self._write(bytes(self.headers))
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write
self._sock.sendall(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
[19/Apr/2019 14:31:21] ERROR [django.server:154] "GET /static/node_modules/metronic-theme-classic/assets/media/logos/favicon.ico HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52185)
Traceback (most recent call last):
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 333, in send_headers
self._write(bytes(self.headers))
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write
self._sock.sendall(b)
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\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 116, in handle_error
super().handle_error()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__
self.handle()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 171, in handle
self.handle_one_request()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request
handler.run(self.server.get_app())
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 111, in close
super().close()
File "C:\Users\azad\AppData\Local\Programs\Python\Python36\lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'

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.

Categories