O
O
Ozrae2020-07-17 21:29:53
Django
Ozrae, 2020-07-17 21:29:53

How to set system variables?

I wanted to deploy my projects to make it easier to view my portfolio. Chose heroku, had no problems until I decided to add system variables and hide secret keys.

I registered system variables like secret key, API keys in the django project settings as it was mentioned in the heroku documentation ( https://devcenter.heroku.com/articles/config-vars#... ), quote:


In Python, using the boto library:
from boto.s3.connection import S3Connection
s3 = S3Connection(os.environ['S3_KEY'], os.environ['S3_SECRET'])

Now, upon deploying to Heroku, the app will use the keys set in the config.


I did the same, added config vars via heroku dashboard, loaded boto library. Registered settings.py, here is an example:
from boto.s3.connection import S3Connection
SECRET_KEY = S3Connection(os.environ['SECRET_KEY'])


How to solve the problem?

Heroku log (not full log, cut off from above, if necessary I can send) gives the following:
2020-07-17T17:11:56.039725+00:00 app[web.1]: application = get_wsgi_application()
2020-07-17T17:11:56.039726+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2020-07-17T17:11:56.039726+00:00 app[web.1]: return WSGIHandler()
2020-07-17T17:11:56.039726+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 127, in __init__
2020-07-17T17:11:56.039727+00:00 app[web.1]: self.load_middleware()
2020-07-17T17:11:56.039727+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 37, 
in load_middleware
2020-07-17T17:11:56.039728+00:00 app[web.1]: mw_instance = middleware(handler)
2020-07-17T17:11:56.039728+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/middleware.py", line 49, in __init__
2020-07-17T17:11:56.039729+00:00 app[web.1]: self.add_files(self.static_root, prefix=self.static_prefix)
2020-07-17T17:11:56.039729+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/base.py", line 113, in add_files
2020-07-17T17:11:56.039729+00:00 app[web.1]: self.update_files_dictionary(root, prefix)
2020-07-17T17:11:56.039730+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/base.py", line 125, in update_files_dictionary
2020-07-17T17:11:56.039730+00:00 app[web.1]: self.add_file_to_dictionary(url, path, stat_cache=stat_cache)
2020-07-17T17:11:56.039730+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/base.py", line 136, in add_file_to_dictionary
2020-07-17T17:11:56.039731+00:00 app[web.1]: static_file = self.get_static_file(path, url, stat_cache=stat_cache)
2020-07-17T17:11:56.039731+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/base.py", line 210, in get_static_file
2020-07-17T17:11:56.039731+00:00 app[web.1]: self.add_cache_headers(headers, path, url)
2020-07-17T17:11:56.039732+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/base.py", line 231, in add_cache_headers
2020-07-17T17:11:56.039732+00:00 app[web.1]: if self.immutable_file_test(path, url):
2020-07-17T17:11:56.039732+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/middleware.py", line 144, in 
immutable_file_test
2020-07-17T17:11:56.039732+00:00 app[web.1]: static_url = self.get_static_url(name_without_hash)
2020-07-17T17:11:56.039733+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/whitenoise/middleware.py", line 167, in 
get_static_url
2020-07-17T17:11:56.039733+00:00 app[web.1]: return decode_if_byte_string(staticfiles_storage.url(name))
2020-07-17T17:11:56.039733+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/storages/backends/s3boto3.py", line 683, in url
2020-07-17T17:11:56.039734+00:00 app[web.1]: url = self.bucket.meta.client.generate_presigned_url('get_object', Params=params,
2020-07-17T17:11:56.039734+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/botocore/signers.py", line 581, in generate_presigned_url
2020-07-17T17:11:56.039734+00:00 app[web.1]: params = self._emit_api_params(params, operation_model, context)
2020-07-17T17:11:56.039735+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/botocore/client.py", line 682, in _emit_api_params
2020-07-17T17:11:56.039735+00:00 app[web.1]: self.meta.events.emit(
2020-07-17T17:11:56.039735+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/botocore/hooks.py", line 356, in emit
2020-07-17T17:11:56.039743+00:00 app[web.1]: return self._emitter.emit(aliased_event_name, **kwargs)
2020-07-17T17:11:56.039744+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/botocore/hooks.py", line 228, in emit
2020-07-17T17:11:56.039744+00:00 app[web.1]: return self._emit(event_name, kwargs)
2020-07-17T17:11:56.039744+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/botocore/hooks.py", line 211, in _emit  
2020-07-17T17:11:56.039745+00:00 app[web.1]: response = handler(**kwargs)
2020-07-17T17:11:56.039745+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/botocore/handlers.py", line 200, in validate_bucket_name
2020-07-17T17:11:56.039745+00:00 app[web.1]: if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket):
2020-07-17T17:11:56.039746+00:00 app[web.1]: TypeError: expected string or bytes-like object
2020-07-17T17:11:56.040144+00:00 app[web.1]: [2020-07-17 17:11:56 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-07-17T17:11:56.216703+00:00 app[web.1]: Traceback (most recent call last):
2020-07-17T17:11:56.216722+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 209, in run  
2020-07-17T17:11:56.217083+00:00 app[web.1]: self.sleep()
2020-07-17T17:11:56.217103+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 357, in sleep2020-07-17T17:11:56.217371+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2020-07-17T17:11:56.217374+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-07-17T17:11:56.217570+00:00 app[web.1]: self.reap_workers()
2020-07-17T17:11:56.217589+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-07-17T17:11:56.217883+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-07-17T17:11:56.217955+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-07-17T17:11:56.217956+00:00 app[web.1]:
2020-07-17T17:11:56.217957+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-07-17T17:11:56.217957+00:00 app[web.1]:
2020-07-17T17:11:56.217960+00:00 app[web.1]: Traceback (most recent call last):
2020-07-17T17:11:56.217962+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2020-07-17T17:11:56.218106+00:00 app[web.1]: sys.exit(run())
2020-07-17T17:11:56.218125+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2020-07-17T17:11:56.218261+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-07-17T17:11:56.218280+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 228, in run 
2020-07-17T17:11:56.218515+00:00 app[web.1]: super().run()
2020-07-17T17:11:56.218519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 72, in run  
2020-07-17T17:11:56.218664+00:00 app[web.1]: Arbiter(self).run()
2020-07-17T17:11:56.218688+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 229, in run  
2020-07-17T17:11:56.218881+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2020-07-17T17:11:56.218902+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 342, in halt 
2020-07-17T17:11:56.219155+00:00 app[web.1]: self.stop()
2020-07-17T17:11:56.219180+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 393, in stop 
2020-07-17T17:11:56.219420+00:00 app[web.1]: time.sleep(0.1)
2020-07-17T17:11:56.219443+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-07-17T17:11:56.219621+00:00 app[web.1]: self.reap_workers()
2020-07-17T17:11:56.219624+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-07-17T17:11:56.219929+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-07-17T17:11:56.219977+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-07-17T17:11:56.323176+00:00 heroku[web.1]: Process exited with status 1
2020-07-17T17:11:56.376185+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-17T17:37:19.787362+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-river-34996.herokuapp.com request_id=002599d9-fe92-49d9-882d-4ebb8895d3cf fwd="85.26.165.149" dyno= connect= service= status=503 bytes= protocol=https        
2020-07-17T17:37:20.239168+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-river-34996.herokuapp.com request_id=57c9b160-4c50-435a-9f05-c1c74bb8f651 fwd="85.26.165.149" dyno= connect= service= status=503 bytes= protocol=https

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-07-17
@dimonchik2013

use sqlite
, or check all the connxins separately, outside of django

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question