ssl error with copying file in s3 server? - django

I tried to collect static files on the S3 Server for my Django project with the command :
python manage.py collectstatic
But It failed because of SSLError :
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\httpsession.py", line 414, in send
chunked=self._chunked(request.headers),
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\util\retry.py", line 507, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\connectionpool.py", line 706, in urlopen
chunked=chunked,
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\connection.py", line 421, in connect
tls_in_tls=tls_in_tls,
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\util\ssl_.py", line 450, in ssl_wrap_socket
sock, context, tls_in_tls, server_hostname=server_hostname
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 423, in wrap_socket
session=session
File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 870, in _create
self.do_handshake()
File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 187, in handle
collected = self.collect()
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 338, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 248, in delete_file
if self.storage.exists(prefixed_path):
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\storages\backends\s3boto3.py", line 469, in exists
self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\client.py", line 395, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\client.py", line 712, in _make_api_call
operation_model, request_dict, request_context)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\client.py", line 731, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\endpoint.py", line 107, in make_request
return self._send_request(request_dict, operation_model)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\endpoint.py", line 184, in _send_request
success_response, exception):
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\endpoint.py", line 308, in _needs_retry
caught_exception=caught_exception, request_dict=request_dict)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\hooks.py", line 357, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\hooks.py", line 211, in _emit
response = handler(**kwargs)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\retryhandler.py", line 192, in __call__
if self._checker(**checker_kwargs):
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\retryhandler.py", line 266, in __call__
caught_exception)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\retryhandler.py", line 292, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\retryhandler.py", line 332, in __call__
caught_exception)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\retryhandler.py", line 232, in __call__
attempt_number, caught_exception)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\retryhandler.py", line 374, in _check_caught_exception
raise caught_exception
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\endpoint.py", line 249, in _do_get_response
http_response = self._send(request)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\endpoint.py", line 321, in _send
return self.http_session.send(request)
File "C:\Users\Anthony\Documents\website_django\venv\lib\site-packages\botocore\httpsession.py", line 432, in send
raise SSLError(endpoint_url=request.url, error=e)
botocore.exceptions.SSLError: SSL validation failed for https://kol-mevasser-content.s3.eu-west-3.amazonaws.com/static/favicon.ico [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)
So I tried to install certifi with pip install certifi but it didn't work.
How can I collect my static files into S3 Server with resolving this SSL Error ?
Here is in my settings.py file :
# (I voluntary put SECRET)
AWS_ACCESS_KEY_ID = "SECRET"
AWS_SECRET_ACCESS_KEY = "SECRET"
AWS_STORAGE_BUCKET_NAME = "SECRET"
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'
AWS_S3_REGION_NAME = 'eu-west-3'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Seems AWS_S3_VERIFY=False setting is what you desire
https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

Related

OSError: [Errno 99] Cannot assign requested address when testing the sendtestemail of kiwi tcms

I am encountering this error below when running the command "docker exec -it kiwi_web /Kiwi/manage.py sendtestemail user1#example1.tld":
OSError: [Errno 99] Cannot assign requested address
I can't find other logs pertaining to this error.
The full error log:
File "/Kiwi/manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/venv/lib64/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/venv/lib64/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/venv/lib64/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/venv/lib64/python3.8/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/venv/lib64/python3.8/site-packages/django/core/management/commands/sendtestemail.py", line 35, in handle
send_mail(
File "/venv/lib64/python3.8/site-packages/django/core/mail/__init__.py", line 87, in send_mail
return mail.send()
File "/venv/lib64/python3.8/site-packages/django/core/mail/message.py", line 298, in send
return self.get_connection(fail_silently).send_messages([self])
File "/venv/lib64/python3.8/site-packages/django/core/mail/backends/smtp.py", line 124, in send_messages
new_conn_created = self.open()
File "/venv/lib64/python3.8/site-packages/django/core/mail/backends/smtp.py", line 80, in open
self.connection = self.connection_class(
File "/usr/lib64/python3.8/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib64/python3.8/smtplib.py", line 337, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib64/python3.8/smtplib.py", line 308, in _get_socket
return socket.create_connection((host, port), timeout,
File "/usr/lib64/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib64/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address

Django API REST error using Postman: "detail": "Authentication credentials were not provided."

EDIT
Operations to perform:
Apply all migrations: admin, auth, authtoken, contenttypes, sessions
Running migrations:
Applying authtoken.0001_initial... OK
Applying authtoken.0002_auto_20160226_1747... OK
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\base.py", line 336, in run_from_argv
connections.close_all()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\utils.py", line 224, in close_all
connection.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable
I learn about Django API REST and have implemented the quickstart project (https://www.django-rest-framework.org/tutorial/quickstart/).
It works fine locally but I would like to use API with Postman but it dose'nt works
I got 401 Unauthorized error
I try adding 'DEFAULT_AUTHENTICATION_CLASSES' key in settings.py but dose'nt works neither
settings.py
INSTALLED_APPS = [
'rest_framework',
'rest_framework.authtoken',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}
moreover, I have a huge traceback in terminal when saving projects (below), even if py manage.py runserver works
Traceback (most recent call last):
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 196, in finish_response
self.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\servers\basehttp.py", line 111, in close
super().close()
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\simple_server.py", line 38, in close
SimpleHandler.close(self)
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 334, in close
self.result.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\http\response.py", line 252, in close
signals.request_finished.send(sender=self._handler_class)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\dispatch\dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\dispatch\dispatcher.py", line 175, in <listcomp>
for receiver in self._live_receivers(sender)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\__init__.py", line 57, in close_old_connections
conn.close_if_unusable_or_obsolete()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\base\base.py", line 514, in close_if_unusable_or_obsolete
self.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable
[02/Sep/2020 16:34:13] "GET /users/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 57191)
Traceback (most recent call last):
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 196, in finish_response
self.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\servers\basehttp.py", line 111, in close
super().close()
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\simple_server.py", line 38, in close
SimpleHandler.close(self)
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 334, in close
self.result.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\http\response.py", line 252, in close
signals.request_finished.send(sender=self._handler_class)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\dispatch\dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\dispatch\dispatcher.py", line 175, in <listcomp>
for receiver in self._live_receivers(sender)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\__init__.py", line 57, in close_old_connections
conn.close_if_unusable_or_obsolete()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\base\base.py", line 514, in close_if_unusable_or_obsolete
self.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\servers\basehttp.py", line 171, in handle
self.handle_one_request()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request
handler.run(self.server.get_app())
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 145, in run
self.handle_error()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\servers\basehttp.py", line 116, in handle_error
super().handle_error()
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 381, in handle_error
self.finish_response()
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 184, in finish_response
self.write(data)
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 287, in write
self.send_headers()
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 344, in send_headers
if not self.origin_server or self.client_is_modern():
File "C:\Users\jl3.PRT-063\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\handlers.py", line 357, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
----------------------------------------
D:\Users\jl3\DevSpace\api_django\tutorial\settings.py changed, reloading.
Traceback (most recent call last):
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 598, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 583, in start_django
reloader.run(django_main_thread)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 301, in run
self.run_loop()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 307, in run_loop
next(ticker)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 355, in tick
self.notify_file_changed(filepath)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 330, in notify_file_changed
trigger_reload(path)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 218, in trigger_reload
sys.exit(3)
SystemExit: 3
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\base.py", line 336, in run_from_argv
connections.close_all()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\utils.py", line 224, in close_all
connection.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable
Traceback (most recent call last):
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\utils\autoreload.py", line 601, in run_with_reloader
sys.exit(exit_code)
SystemExit: 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\core\management\base.py", line 336, in run_from_argv
connections.close_all()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\utils.py", line 224, in close_all
connection.close()
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
File "C:\Users\jl3.PRT-063\Desktop\Python\Django\env\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable
First, you are going to have to create a token for the user you are trying to log in as.
from rest_framework.authtoken.models import Token
token = Token.objects.create(user=...)
print(token.key)
Then you want to include that token in your url head
curl -X GET http://127.0.0.1:8000/api/example/ -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'
Here is some documentation look under TokenAuthentication.
https://www.django-rest-framework.org/api-guide/authentication/
In post man you can just click the header box and type in your token there. This should authenticate you, you just have to generate the token for your user first.
Here is a link to some documentation on how to work with common authentication types with postman. https://learning.postman.com/docs/sending-requests/authorization/#basic-auth
Try this one.
python3 manage.py migrate

Django boto3 error during collectstatic command

I'm trying to run a gitlab project on a local machine. I have a problem at the start of the command
manage.py collectstatic
error
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
collected = self.collect()
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 260, in delete_file
if self.storage.exists(prefixed_path):
File "/home/y700/Env/healthline/lib/python3.7/site-packages/storages/backends/s3boto3.py", line 532, in exists
self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 634, in _make_api_call
api_params, operation_model, context=request_context)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 680, in _convert_to_request_dict
api_params, operation_model, context)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 712, in _emit_api_params
params=api_params, model=operation_model, context=context)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/hooks.py", line 211, in _emit
response = handler(**kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/handlers.py", line 219, in validate_bucket_name
if VALID_BUCKET.search(bucket) is None:
TypeError: expected string or bytes-like object
I tried to update the boto3 version, but it didn't help.
settings.py (part)
....
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'app', 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
....
else I have settings for AWS server
AWS_LOCATION = 'static'
DEFAULT_FILE_STORAGE = 'app.storage_backends.PrivateMediaStorage'
AWS_PUBLIC_STATIC_LOCATION = 'static/'

flask apns - SysCallError: (-1, 'Unexpected EOF')

I'm trying to use Flask-APNS, previously I check that my ck.pem (cert and key on one file) works on a php server.
But everytime I try to execute:
from apns import APNS
#apns = APNS(app, cert_file='ZivingCert.pem', key_file='ZivingKey.pem',passphrase='mypassphrase')
apns = APNS(app, cert_file='ck.pem', passphrase='mypassphrase')
apns.send_message(tokens=['fad71c0b27416f055bfb1617c8db4e55d1b98b412443e68fba65cfe59748b81a'], alert='hi world', extra={})
I get this error:
WARNING:apnsclient.backends.stdio:Failed to establish socket/SSL connection to ('gateway.sandbox.push.apple.com', 2195)
No handlers could be found for logger "apnsclient.backends.stdio"
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 263, in error_router
return original_handler(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 260, in error_router
return self.handle_error(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 263, in error_router
return original_handler(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 260, in error_router
return self.handle_error(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 431, in wrapper
resp = resource(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_httpauth.py", line 60, in decorated
return f(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 521, in dispatch_request
resp = meth(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/scheduler/ws/v1/schedulesapns.py", line 21, in get
apns.send_message(tokens=['fad71c0b27416f055bfb1617c8db4e55d1b98b412443e68fba65cfe59748b81a'], alert='hi world', extra={})
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/scheduler/apns/__init__.py", line 134, in send_message
res = srv.send(message)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/apns.py", line 90, in send
status = self._connection.send(message)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 255, in send
with self:
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 228, in __enter__
self._open_connection() # can raise exception, bubblit up to the top
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 519, in _open_connection
timeout=self.session.connect_timeout
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/__init__.py", line 88, in get_cached_connection
return self.get_new_connection(address, certificate, timeout=timeout)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 378, in get_new_connection
return self.connection_class(address, certificate, timeout=timeout)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 142, in __init__
self._open_connection(timeout)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 153, in _open_connection
self._connect_and_handshake()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 188, in _connect_and_handshake
self._connection.do_handshake()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1442, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1180, in _raise_ssl_error
raise SysCallError(-1, "Unexpected EOF")
SysCallError: (-1, 'Unexpected EOF')
I finally fixed thanks to logging messages.
To enable logging:
import logging
logging.basicConfig()
To fix WARNING:apnsclient.backends.stdio:Failed to establish socket/SSL connection to ('gateway.sandbox.push.apple.com', 2195) caused by security issue with SSL version 3.0 the Apple Push Notification server remove support for SSL 3.0 since Wednesday, October 29 of 2014.
def my_callback(key, reason):
print "my_callbaaaaaaack"
print str(key)
print str(reason)
import OpenSSL
OpenSSL.SSL.SSLv3_METHOD = OpenSSL.SSL.TLSv1_METHOD
from apns import APNS
apns = APNS(app, cert_file='ck.pem', passphrase='mypassphrase', failure_callback=my_callback)

Haystack UnicodeDecodeError

I'm using haystack and solr on Django. I get UnicodeDecodeError and I think the reason is the unicode data in the database are either converted to str or decoded to utf-8 which makes a later UnicodeDecodeError when sending via httplib or printing to the console.
I think the problem should before the haystack full_prepare function, since as I checked afterwards data is already ruined.
Any thoughts?
I setup.pyed install (haystack, pysolr, django)
and used the binary of lxml from http://www.lfd.uci.edu/~gohlke/pythonlibs/
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Pouria\Desktop\conference\conference>python manage.py rebuild_index
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
Failed to clear Solr index: [Reason: Error 404 Not Found]
All documents removed.
C:\Python27\lib\site-packages\django\db\models\fields\__init__.py:808: RuntimeWarning: DateTimeField
received a naive datetime (2013-02-09 08:47:27.110000) while time zone support is active.
RuntimeWarning)
Indexing 2 conferences.
ERROR:root:Error updating conferences using default
Traceback (most recent call last):
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py",
line 210, in handle_label
self.update_backend(label, using)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py",
line 256, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py",
line 78, in do_update
backend.update(index, current_qs)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\backends\solr_backend.py", line 72, i
n update
self.conn.add(docs, commit=commit, boost=index.get_field_weights())
File "C:\Python27\lib\site-packages\pysolr.py", line 786, in add
return self._update(m, commit=commit, waitFlush=waitFlush, waitSearcher=waitSearcher)
File "C:\Python27\lib\site-packages\pysolr.py", line 379, in _update
return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
File "C:\Python27\lib\site-packages\pysolr.py", line 291, in _send_request
timeout=self.timeout)
File "C:\Python27\lib\site-packages\requests\api.py", line 87, in post
return request('post', url, data=data, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies
)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 373, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 171, in send
timeout=timeout
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 421, in url
open
body=body, headers=headers)
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 273, in _ma
ke_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python27\lib\httplib.py", line 949, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 990, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 943, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 810, in _send_output
self.send(message_body)
File "C:\Python27\lib\httplib.py", line 775, in send
self.sock.sendall(str)
File "C:\Python27\lib\socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 143-149: ordinal not in range(
128)
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from
_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\rebuild_index.py"
, line 15, in handle
call_command('update_index', **options)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py",
line 184, in handle
return super(Command, self).handle(*items, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 341, in handle
label_output = self.handle_label(label, **options)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py",
line 210, in handle_label
self.update_backend(label, using)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py",
line 256, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py",
line 78, in do_update
backend.update(index, current_qs)
File "C:\Users\Pouria\Desktop\conference\conference\haystack\backends\solr_backend.py", line 72, i
n update
self.conn.add(docs, commit=commit, boost=index.get_field_weights())
File "C:\Python27\lib\site-packages\pysolr.py", line 786, in add
return self._update(m, commit=commit, waitFlush=waitFlush, waitSearcher=waitSearcher)
File "C:\Python27\lib\site-packages\pysolr.py", line 379, in _update
return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
File "C:\Python27\lib\site-packages\pysolr.py", line 291, in _send_request
timeout=self.timeout)
File "C:\Python27\lib\site-packages\requests\api.py", line 87, in post
return request('post', url, data=data, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies
)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 373, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 171, in send
timeout=timeout
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 421, in url
open
body=body, headers=headers)
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 273, in _ma
ke_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python27\lib\httplib.py", line 949, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 990, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 943, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 810, in _send_output
self.send(message_body)
File "C:\Python27\lib\httplib.py", line 775, in send
self.sock.sendall(str)
File "C:\Python27\lib\socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 143-149: ordinal not in range(
128)
I had the same error. It's seams to be fixed on master https://github.com/toastdriven/django-haystack. So you should use haystack 2.0 alpha/beta.