Heroku: string without NULL bytes with several requirements files - django

I'm trying to deploy a Django web application in Heroku from Ubuntu following the "Two scoops of Django 1.6" project structure.
After doing heroku create, I run git push heroku master and I get the output attached at the end.
I googled extensively and I'm aware that the error is this
TypeError: must be encoded string without NULL bytes, not str
and it is caused because some encoding or rare characters in requirements files. My problem is that I tried saving with less dependencies and changing encodings in the files and achieved nothing (I don't know the valid encodings for Heroku, so I'm blind at this).
I'm looking for a way of finding the null characters, even with cat -e at the command line, but I can't find anything. I'm asking for a way for finding the encoding problem or the wrong dependency.
Thank you in advanced.
EDIT: I tried doing pip
install -r <fileName>.txt
with several of my requirements txt files. All the installations were fine. I also tried doing the git push heroku master with all commented in the main requirements.txt (an empty file) and it keeps giving the same error. Maybe heroku is not picking the requirements.txt file???
I tried re-creating the files from command line and typing manually the same content (not copy-paste). The same error keeps appearing. :-(
Files and output:
My requirements files are:
requirements.txt (at the very root of the project):
# This file is here because many Platforms as a Service look for
# requirements.txt in the root directory of a project.
-r requirements/production.txt
requirements/production.txt:
# Pro-tip: Try not to put anything here. There should be no dependency in
# production that isn't in development.
-r base.txt
gunicorn==18.0
and requirements/base.txt:
Django==1.7
psycopg2==2.6
sqlparse==0.1.15
django-debug-toolbar==1.3.0
html5lib==0.999
Pillow==2.8.1
PyPDF2==1.24
reportlab==3.1.44
six==1.9.0
xhtml2pdf==0.0.6
the output:
Pushing to https://git.heroku.com/tranquil-cliffs-3699.git
POST git-receive-pack (chunked)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing runtime (python-2.7.10)
remote: -----> Installing dependencies with pip
remote: Exception:
remote: Traceback (most recent call last):
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/basecommand.py", line 223, in main
remote: status = self.run(options, args)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/commands/install.py", line 268, in run
remote: wheel_cache
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/basecommand.py", line 287, in populate_requirement_set
remote: wheel_cache=wheel_cache):
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/req/req_file.py", line 86, in parse_requirements
remote: for req in req_iter:
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/req/req_file.py", line 161, in process_line
remote: for req in parser:
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/req/req_file.py", line 86, in parse_requirements
remote: for req in req_iter:
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/req/req_file.py", line 161, in process_line
remote: for req in parser:
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/req/req_file.py", line 86, in parse_requirements
remote: for req in req_iter:
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/req/req_file.py", line 130, in process_line
remote: wheel_cache=wheel_cache
remote: File "/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.1-py2.7.egg/pip/req/req_install.py", line 162, in from_line
remote: if (os.path.isdir(p) and
remote: File "/app/.heroku/python/lib/python2.7/genericpath.py", line 49, in isdir[K
remote: st = os.stat(s)
remote: TypeError: must be encoded string without NULL bytes, not str
remote:
remote:
remote: ! Push rejected, failed to compile Python app
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to tranquil-cliffs-3699.
remote:
To https://git.heroku.com/tranquil-cliffs-3699.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/tranquil-cliffs-3699.git'

It was all my fault. Super-newbie stupid error. I was not making git commit after each edit, so I was pushing always the same wrong files to Heroku.
Now I finally realized, and when pushing the error has changed to another one.
Thanks a lot for your help and sorry for making you lose your time.

Related

how to fix Heroku error when trying to push -- pre-receive hook declined

I was trying to push what i have in my app using Django python to be deployed to Heroku and keep getting this error :
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/immense-brushlands'
requriment.txt file is there :
asgiref==3.4.1
beautifulsoup4==4.10.0
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.7
cloudinary==1.26.0
cryptography==35.0.0
defusedxml==0.7.1
Deprecated==1.2.13
dj-database-url==0.5.0
Django==3.2.5
django-bootstrap4==3.0.1
django-braces==1.14.0
django-heroku==0.3.1
django-oauth-toolkit==1.5.0
django-rest-framework-social-oauth2==1.1.0
djangorestframework==3.12.4
gunicorn==20.1.0
idna==3.3
jwcrypto==1.0
oauthlib==3.1.1
psycopg2==2.9.1
pycparser==2.20
PyJWT==2.3.0
python3-openid==3.2.0
pytz==2021.3
requests==2.26.0
requests-oauthlib==1.3.0
six==1.16.0
social-auth-app-django==5.0.0
social-auth-core==4.1.0
soupsieve==2.2.1
sqlparse==0.4.2
stripe==2.59.0
urllib3==1.26.7
whitenoise==5.3.0
wrapt==1.13.2
my Procfile in root directory and contain:
web : gunicorn foodhub.wsgi
I was trying to push what i have in my app using Django python to be deployed to Heroku and keep getting this error :
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/immense-brushlands'`
-----> Building on the Heroku-22 stack
-----> Determining which buildpack to use for this app
-----> Python app detected
-----> No Python version was specified. Using the buildpack default: python-3.10.7
To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
-----> Installing python-3.10.7
-----> Installing pip 22.2.2, setuptools 63.4.3 and wheel 0.37.1
-----> Installing SQLite3
-----> Installing requirements with pip
Collecting asgiref==3.5.2
Downloading asgiref-3.5.2-py3-none-any.whl (22 kB)
Collecting certifi==2022.9.24
Downloading certifi-2022.9.24-py3-none-any.whl (161 kB)
Collecting cloudinary==1.26.0
Downloading cloudinary-1.26.0.tar.gz (170 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting dj-database-url==1.0.0
Downloading dj_database_url-1.0.0-py3-none-any.whl (6.6 kB)
Collecting Django==4.1.2
Downloading Django-4.1.2-py3-none-any.whl (8.1 MB)
Collecting django-heroku==0.3.1
Downloading django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
Collecting gunicorn==20.1.0
Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
Collecting psycopg2==2.9.4
Downloading psycopg2-2.9.4.tar.gz (384 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting six==1.16.0
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting sqlparse==0.4.3
Downloading sqlparse-0.4.3-py3-none-any.whl (42 kB)
Collecting tzdata==2022.4
Downloading tzdata-2022.4-py2.py3-none-any.whl (336 kB)
Collecting urllib3==1.26.12
Downloading urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
Collecting whitenoise==6.2.0
Downloading whitenoise-6.2.0-py3-none-any.whl (19 kB)
Building wheels for collected packages: cloudinary, psycopg2
Building wheel for cloudinary (setup.py): started
Building wheel for cloudinary (setup.py): finished with status 'done'
Created wheel for cloudinary: filename=cloudinary-1.26.0-py3-none-any.whl size=134187 sha256=391663ac9f9caa29fca028ee944bf59a6ac5066a9aa1012fb188ff52dac36979
Stored in directory: /tmp/pip-ephem-wheel-cache-odd2a9t_/wheels/58/0d/32/997fc6c26f83c9ae73a1bcd41028973512175982df608523ef
Building wheel for psycopg2 (setup.py): started
Building wheel for psycopg2 (setup.py): finished with status 'done'
Created wheel for psycopg2: filename=psycopg2-2.9.4-cp310-cp310-linux_x86_64.whl size=159965 sha256=cae6fb7d596d71258bdd30d91a0aa6ec5e8d5ba26d5c2c8f9601e00eb569ea53
Stored in directory: /tmp/pip-ephem-wheel-cache-odd2a9t_/wheels/10/07/ca/a5e7863aeec605e8a19ea9ccc90bb594784c287cc5534bbecb
Successfully built cloudinary psycopg2
Installing collected packages: whitenoise, urllib3, tzdata, sqlparse, six, psycopg2, gunicorn, certifi, asgiref, Django, cloudinary, dj-database-url, django-heroku
Successfully installed Django-4.1.2 asgiref-3.5.2 certifi-2022.9.24 cloudinary-1.26.0 dj-database-url-1.0.0 django-heroku-0.3.1 gunicorn-20.1.0 psycopg2-2.9.4 six-1.16.0 sqlparse-0.4.3 tzdata-2022.4 urllib3-1.26.12 whitenoise-6.2.0
-----> $ python manage.py collectstatic --noinput
Post-processing 'js/canvas-to-blob.min.js' failed!
Traceback (most recent call last):
File "/tmp/build_b3caaaea/manage.py", line 22, in <module>
main()
File "/tmp/build_b3caaaea/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 154, in collect
raise processed
whitenoise.storage.MissingFileError: The file 'js/canvas-to-blob.min.js.map' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7ff53e881d50>.
The JS file 'js/canvas-to-blob.min.js' references a file which could not be found:
js/canvas-to-blob.min.js.map
Please check the URL references in this JS file, particularly any
relative paths which might be pointing to the wrong location.
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
****** Collectstatic environment variables:
PYTHONUNBUFFERED=1
PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:
DEBUG_COLLECTSTATIC=1
BPLOG_PREFIX=buildpack.python
PWD=/tmp/build_b3caaaea
HOME=/app
LANG=en_US.UTF-8
SOURCE_VERSION=495ce7e183efedd2df883a898d49dab71e966050
REQUEST_ID=9bd57211-cb18-3350-055d-aa2d6bfe888e
ENV_DIR=/tmp/d20221008-54-7rg3a6
PYTHONPATH=.
CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
BIN_DIR=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin
LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
SHLVL=1
LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
PIP_NO_PYTHON_VERSION_WARNING=1
BUILDPACK_LOG_FILE=/dev/null
STACK=heroku-22
BUILD_DIR=/tmp/build_b3caaaea
CACHE_DIR=/tmp/codon/tmp/cache
PATH=/app/.heroku/python/bin:/app/.heroku/vendor/bin::/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/
EXPORT_PATH=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin/../export
C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
DYNO=run.5378
PROFILE_PATH=/tmp/build_b3caaaea/.profile.d/python.sh
OLDPWD=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136
_=/usr/bin/env
! Push rejected, failed to compile Python app.
! Push failed
remote: Collecting tzdata==2022.4
remote: Downloading tzdata-2022.4-py2.py3-none-any.whl (336 kB)
remote: Collecting urllib3==1.26.12
remote: Downloading urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
remote: Collecting whitenoise==6.2.0
remote: Downloading whitenoise-6.2.0-py3-none-any.whl (19 kB)
remote: Building wheels for collected packages: cloudinary, psycopg2
remote: Building wheel for cloudinary (setup.py): started
remote: Building wheel for cloudinary (setup.py): finished with status 'done'
remote: Created wheel for cloudinary: filename=cloudinary-1.26.0-py3-none-any.whl size=134187 sha256=a8e60aba890ebec526fa450889f89331a3f91deb0951c91ab9e6cbcf4452cf43
remote: Stored in directory: /tmp/pip-ephem-wheel-cache-nqiyqf0q/wheels/58/0d/32/997fc6c26f83c9ae73a1bcd41028973512175982df608523ef
remote: Building wheel for psycopg2 (setup.py): started
remote: Building wheel for psycopg2 (setup.py): finished with status 'done'
remote: Created wheel for psycopg2: filename=psycopg2-2.9.4-cp310-cp310-linux_x86_64.whl size=159965 sha256=8087037db2c9ec2fdbae93eb5afd833509bbcbdbd546e980794242a06e01b87a
remote: Stored in directory: /tmp/pip-ephem-wheel-cache-nqiyqf0q/wheels/10/07/ca/a5e7863aeec605e8a19ea9ccc90bb594784c287cc5534bbecb
remote: Successfully built cloudinary psycopg2
remote: Installing collected packages: whitenoise, urllib3, tzdata, sqlparse, six, psycopg2, gunicorn, certifi, asgiref, Django, cloudinary, dj-database-url, django-heroku
remote: Successfully installed Django-4.1.2 asgiref-3.5.2 certifi-2022.9.24 cloudinary-1.26.0 dj-database-url-1.0.0 django-heroku-0.3.1 gunicorn-20.1.0 psycopg2-2.9.4 six-1.16.0 sqlparse-0.4.3 tzdata-2022.4 urllib3-1.26.12 whitenoise-6.2.0
remote: -----> $ python manage.py collectstatic --noinput
remote: Post-processing 'js/load-image.all.min.js' failed!
remote: Traceback (most recent call last):
remote: File "/tmp/build_f2d02e58/manage.py", line 22, in <module>
remote: main()
remote: File "/tmp/build_f2d02e58/manage.py", line 18, in main
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
remote: self.execute(*args, **cmd_options)
remote: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
remote: output = self.handle(*args, **options)
remote: File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
remote: collected = self.collect()
remote: File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 154, in collect
remote: raise processed
remote: whitenoise.storage.MissingFileError: The file 'js/load-image.all.min.js.map' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f5b6e77dd50>.
remote: The JS file 'js/load-image.all.min.js' references a file which could not be found:
remote: js/load-image.all.min.js.map
remote: Please check the URL references in this JS file, particularly any
remote: relative paths which might be pointing to the wrong location.
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote:
remote: ****** Collectstatic environment variables:
remote:
remote: PYTHONUNBUFFERED=1
remote: PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:
remote: DEBUG_COLLECTSTATIC=1
remote: BPLOG_PREFIX=buildpack.python
remote: PWD=/tmp/build_f2d02e58
remote: HOME=/app
remote: LANG=en_US.UTF-8
remote: SOURCE_VERSION=495ce7e183efedd2df883a898d49dab71e966050
remote: REQUEST_ID=8dbf04e4-d06f-2a07-26fd-fd9f783c0707
remote: ENV_DIR=/tmp/d20221008-55-86y9b6
remote: PYTHONPATH=.
remote: CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
remote: BIN_DIR=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin
remote: LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
remote: SHLVL=1
remote: LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
remote: PIP_NO_PYTHON_VERSION_WARNING=1
remote: BUILDPACK_LOG_FILE=/dev/null
remote: STACK=heroku-22
remote: BUILD_DIR=/tmp/build_f2d02e58
remote: CACHE_DIR=/tmp/codon/tmp/cache
remote: PATH=/app/.heroku/python/bin:/app/.heroku/vendor/bin::/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/
remote: EXPORT_PATH=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin/../export
remote: C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
remote: DYNO=run.5998
remote: PROFILE_PATH=/tmp/build_f2d02e58/.profile.d/python.sh
remote: OLDPWD=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136
remote: _=/usr/bin/env
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 495ce7e183efedd2df883a898d49dab71e966050
remote: !
remote: ! We have detected that you have triggered a build from source code with version 495ce7e183efedd2df883a898d49dab71e966050
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to immense-brushlands-83439.
remote:
To https://git.heroku.com/immense-brushlands-83439.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/immense-brushlands-83439.git'

No Procfile and no package.json file found in Current Directory - See run-foreman.js

I am trying to deploy a django app to heroku, and it is causing me errors. In the process of debugging when I run the command
heroku local web -f Procfile.windows
it shows me the following error:
[FAIL] No Procfile and no package.json file found in Current Directory - See run-foreman.js --help
From the application structure that is attached you can see that there is the Proc file and the content of the Procfile is as following:
web: gunicorn klaviyo_integration.wsgi --log-file -
Any guesses what might be wrong?
And I am using Windows as OS, in case there is a problem with gunicorn on that sense.
It might caused by wrong Procfile syntax.
Try to remove any comment from your Procfile. It works in my case.
My original Procfile:
# Some comment here
web: python start.py --port %PORT%
After removing the comment, no more errors occur.
web: python start.py --port %PORT%
I had same problem with tmp directory.
I could solve it by removing from .gitignore. check Procfile in .gitignore
BLUF: Try verifying your Procfile is actually saved as a UTF-8 file
How to debug your issue better:
This is a generic error heroku-cli returns whenever it can't parse your Procfile, and unfortunately it's logging does a poor job of telling you what the problem is.
For me, I ran into this error when I tried creating the Procfile in Pycharm on Windows
$ heroku local
[WARN] Cannot read property '1' of null
[FAIL] No Procfile and no package.json file found in Current Directory - See run --help
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Index.run (/usr/local/lib/heroku/node_modules/#heroku-cli/plugin-local/lib/commands/local/index.js:30:38)
at Index._run (/usr/local/lib/heroku/node_modules/#oclif/command/lib/command.js:44:31)
Turns out, the heroku server is gives much better error messages!
When I tried pushing the changes directly to heroku that I got a real lead towards the true root cause:
$ git push heroku main
Counting objects: 102, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (96/96), done.
Writing objects: 100% (102/102), 33.93 KiB | 808.00 KiB/s, done.
Total 102 (delta 31), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
git bremote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Python app detected
remote: -----> Using Python version specified in runtime.txt
remote: Traceback (most recent call last):
remote: File "/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/runtime-fixer", line 8, in <module>
remote: r = f.read().strip()
remote: File "/usr/lib/python3.8/codecs.py", line 322, in decode
remote: (result, consumed) = self._buffer_decode(data, self.errors, final)
remote: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
remote: /tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin/steps/python: line 5: warning: command substitution: ignored null byte in input
remote: ) is not available for this stack (heroku-20).
remote: ! Aborting. More info: https://devcenter.heroku.com/articles/python-support
remote: ! Push rejected, failed to compile Python app.
remote:
rremote: ! Push failed
anremote: Verifying deploy...
remote:
remote: ! Push rejected to salty-ocean-58897.
remote:
To https://git.heroku.com/salty-ocean-58897.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/salty-ocean-58897.git'
Specifically, note the line:
remote: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
That's what pointed me in the right direction and led me to realizing Pycharm had created my Procfile, runtime.txt, and requirements.txt files as utf-16 files. Converting them to utf-8 fixed the error.

Unable to deploy Django app in Heroku due to requirements.txt error

I am trying to deploy a django app I created to heroku. When i do git push heroku master an error shows remote: cp: cannot create regular file '/app/tmp/cache/.heroku/requirements.txt': No such file or directory.
here is the full log:
Enumerating objects: 35, done.
Counting objects: 100% (35/35), done.
Delta compression using up to 2 threads
Compressing objects: 100% (32/32), done.
Writing objects: 100% (35/35), 12.68 KiB | 405.00 KiB/s, done.
Total 35 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: cp: cannot create regular file '/app/tmp/cache/.heroku/requirements.txt': No such file or directory
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Installing requirements with pip
remote: Collecting asgiref==3.2.7
remote: Downloading asgiref-3.2.7-py2.py3-none-any.whl (19 kB)
remote: Collecting astroid==2.3.3
remote: Downloading astroid-2.3.3-py3-none-any.whl (205 kB)
remote: Collecting colorama==0.4.3
remote: Downloading colorama-0.4.3-py2.py3-none-any.whl (15 kB)
remote: Collecting dj-database-url==0.5.0
remote: Downloading dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
remote: Collecting Django==3.0.5
remote: Downloading Django-3.0.5-py3-none-any.whl (7.5 MB)
remote: Collecting django-heroku==0.3.1
remote: Downloading django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
remote: Collecting gunicorn==20.0.4
remote: Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
remote: Collecting isort==4.3.21
remote: Downloading isort-4.3.21-py2.py3-none-any.whl (42 kB)
remote: Collecting lazy-object-proxy==1.4.3
remote: Downloading lazy_object_proxy-1.4.3-cp36-cp36m-manylinux1_x86_64.whl (55 kB)
remote: Collecting mccabe==0.6.1
remote: Downloading mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
remote: Collecting psycopg2==2.8.5
remote: Downloading psycopg2-2.8.5.tar.gz (380 kB)
remote: Collecting pylint==2.4.4
remote: Downloading pylint-2.4.4-py3-none-any.whl (302 kB)
remote: Collecting pytz==2019.3
remote: Downloading pytz-2019.3-py2.py3-none-any.whl (509 kB)
remote: Collecting six==1.14.0
remote: Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
remote: Collecting sqlparse==0.3.1
remote: Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
remote: Collecting typed-ast==1.4.1
remote: Downloading typed_ast-1.4.1-cp36-cp36m-manylinux1_x86_64.whl (737 kB)
remote: Collecting whitenoise==5.0.1
remote: Downloading whitenoise-5.0.1-py2.py3-none-any.whl (20 kB)
remote: Collecting wrapt==1.11.2
remote: Downloading wrapt-1.11.2.tar.gz (27 kB)
remote: Building wheels for collected packages: psycopg2, wrapt
remote: Building wheel for psycopg2 (setup.py): started
remote: Building wheel for psycopg2 (setup.py): finished with status 'done'
remote: Created wheel for psycopg2: filename=psycopg2-2.8.5-cp36-cp36m-linux_x86_64.whl size=447249 sha256=8c3101c70eafd1ccd9ef08021cf553d3c10d55ac62b1c191b19735ab3c026e5a
remote: Stored in directory: /tmp/pip-ephem-wheel-cache-025326ex/wheels/52/9a/ab/22a0d1dc560ad5c0d09cc1c968015f89726e7e01c190dee110
remote: Building wheel for wrapt (setup.py): started
remote: Building wheel for wrapt (setup.py): finished with status 'done'
remote: Created wheel for wrapt: filename=wrapt-1.11.2-cp36-cp36m-linux_x86_64.whl size=69767 sha256=974a65540f5d88c324d2c7cd1c4379cbaa7e2c1a03e599864be4c2ffbe4e17af
remote: Stored in directory: /tmp/pip-ephem-wheel-cache-025326ex/wheels/0d/85/48/15d7bfab92a2d0e87372224c1f628fc57db7447a663a58e86c
remote: Successfully built psycopg2 wrapt
remote: Installing collected packages: asgiref, lazy-object-proxy, typed-ast, six, wrapt, astroid, colorama, dj-database-url, sqlparse, pytz, Django, psycopg2, whitenoise, django-heroku, gunicorn, isort, mccabe, pylint
remote: Successfully installed Django-3.0.5 asgiref-3.2.7 astroid-2.3.3 colorama-0.4.3 dj-database-url-0.5.0 django-heroku-0.3.1 gunicorn-20.0.4 isort-4.3.21 lazy-object-proxy-1.4.3 mccabe-0.6.1 psycopg2-2.8.5 pylint-2.4.4 pytz-2019.3 six-1.14.0 sqlparse-0.3.1 typed-ast-1.4.1 whitenoise-5.0.1 wrapt-1.11.2
remote: -----> $ python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "manage.py", line 21, in <module>
remote: main()
remote: File "manage.py", line 17, in main
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
remote: self.execute(*args, **cmd_options)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute
remote: output = self.handle(*args, **options)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
remote: collected = self.collect()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 104, in collect
remote: for path, storage in finder.list(self.ignore_patterns):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 130, in list
remote: for path in utils.get_files(storage, ignore_patterns):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
remote: directories, files = storage.listdir(location)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 316, in listdir
remote: for entry in os.scandir(path):
remote: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_8b272f59d204dc1b5699579647b39ae3/static_in_env'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to pure-plains-36964.
remote:
To https://git.heroku.com/pure-plains-36964.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/pure-plains-36964.git'
I do have requirements.txt in my root directory with everything included. Please help
There is indeed a requirements.txt error but that does not stop the build.
The error is something with your django collectstatic. Might be because you have an empty folder in called static_in_env. You may follow the recommendation in the stack trace, i.e. run:
$ heroku config:set DISABLE_COLLECTSTATIC=1
But if you need the collectstatic to run then revert that flag:
$ heroku config:set DISABLE_COLLECTSTATIC=0
and then debug why it is empty. It is hard to tell without more context.
As for the requirements.txt, make sure you only have one requirements.txt. If you have more than one, make sure they all have some text in them. Hope this helps.

Unable to deploy of Heroku because of Python Package with Error

I'm trying to upload my django application on Heroku. It works on local because I corrected the error, but for some reason after I added whitenoise to get local files so that I can deploy on Heroku, it keeps bringing up the same error.
I am loading a local package csv-imports and it has an error on line 70.
class ImportModel(models.Model):
""" Optional one to one mapper of import file to Model """
#this is the line with the error and I fixed it here with the on_delete
csvimport = models.ForeignKey(CSVImport, on_delete=models.DO_NOTHING)
numeric_id = models.PositiveIntegerField()
natural_key = models.CharField(max_length=100)
However when I run:
git push heroku master
I get the following error which I have fixed on my local, but seems to keep coming up with Heroku. The file has been changed. I might not be on the right file path given by Heroku there is no app/.heroku/ on my computer. But, there is only one installation of csv-imports on my computer and that one has been fixed as above. Why do I keep getting this error and how do I fix it?
remote: File "/app/.heroku/python/lib/python3.7/site-packages/csvimport/models.py", line 72, in ImportModel
remote: csvimport = models.ForeignKey(CSVImport)
remote: TypeError: __init__() missing 1 required positional argument: 'on_delete'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
emote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to gentle-lowlands-98196.
remote:
Problem is with your static directory, first you have to run:
"python manage.py collectstatic"
This will give you the path of your static directory or an exception like you are using STATIC_URL without STATIC_ROOT Directory.

`collectstatic` error when deploying Django app to heroku

While deploying my Django app to heroku, but colletstatic method seems to throw lots of errors. I've tried several solutions posted online but none worked. By the way, I'm using whitenoise for serving my static files.
Counting objects: 77, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (74/74), done.
Writing objects: 100% (77/77), 351.57 KiB | 0 bytes/s, done.
Total 77 (delta 27), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.1
remote: -----> Installing pip
remote: -----> Installing requirements with pip
remote: Collecting Django==1.11.1 (from -r /tmp/build_d86f80f6593040bde7f9cb90828051e6/requirements.txt (line 1))
remote: Downloading Django-1.11.1-py2.py3-none-any.whl (6.9MB)
remote: Collecting gunicorn==19.7.1 (from -r /tmp/build_d86f80f6593040bde7f9cb90828051e6/requirements.txt (line 2))
remote: Downloading gunicorn-19.7.1-py2.py3-none-any.whl (111kB)
remote: Collecting whitenoise==3.3.0 (from -r /tmp/build_d86f80f6593040bde7f9cb90828051e6/requirements.txt (line 3))
remote: Downloading whitenoise-3.3.0-py2.py3-none-any.whl
remote: Collecting psycopg2==2.7.1 (from -r /tmp/build_d86f80f6593040bde7f9cb90828051e6/requirements.txt (line 4))
remote: Downloading psycopg2-2.7.1-cp36-cp36m-manylinux1_x86_64.whl (2.7MB)
remote: Collecting pytz (from Django==1.11.1->-r /tmp/build_d86f80f6593040bde7f9cb90828051e6/requirements.txt (line 1))
remote: Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
remote: Installing collected packages: pytz, Django, gunicorn, whitenoise, psycopg2
remote: Successfully installed Django-1.11.1 gunicorn-19.7.1 psycopg2-2.7.1 pytz-2017.2 whitenoise-3.3.0
remote:
remote: -----> $ python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "manage.py", line 22, in <module>
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
remote: self.execute(*args, **cmd_options)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
remote: output = self.handle(*args, **options)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
remote: collected = self.collect()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 115, in collect
remote: for path, storage in finder.list(self.ignore_patterns):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
remote: for path in utils.get_files(storage, ignore_patterns):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
remote: directories, files = storage.listdir(location)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 397, in listdir
remote: for entry in os.listdir(path):
remote: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_d86f80f6593040bde7f9cb90828051e6/Nostradamus/static'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote:
remote: ****** Collectstatic environment variables:
remote:
remote: CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
remote: EXPORT_PATH=/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/bin/../export
remote: SOURCE_VERSION=438c510c80b83b0d88b66ca02b9c8563e930b185
remote: PROFILE_PATH=/tmp/build_d86f80f6593040bde7f9cb90828051e6/.profile.d/python.sh
remote: DEBUG_COLLECTSTATIC=0
remote: BUILDPACK_LOG_FILE=/dev/fd/3
remote: LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
remote: CACHE_DIR=/app/tmp/cache
remote: PYTHONUNBUFFERED=1
remote: PYHONHOME=/tmp/build_d86f80f6593040bde7f9cb90828051e6/.heroku/python
remote: LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
remote: BIN_DIR=/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/bin
remote: DYNO=run.7199
remote: PATH=/app/.heroku/python/bin:/app/.heroku/vendor/bin::/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/tmp/codon/vendor/bin:/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/:/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pip-pop
remote: RECOMMENDED_PYTHON_VERSION=python-2.7.13
remote: C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
remote: PWD=/tmp/build_d86f80f6593040bde7f9cb90828051e6
remote: BPLOG_PREFIX=buildpack.python
remote: LANG=en_US.UTF-8
remote: STACK=heroku-16
remote: SHLVL=3
remote: REQUEST_ID=27f7a88e-8898-45ab-b6ef-d7792fdb0a7a
remote: HOME=/app
remote: PYTHONPATH=/tmp/build_d86f80f6593040bde7f9cb90828051e6/
remote: BUILD_DIR=/tmp/build_d86f80f6593040bde7f9cb90828051e6
remote: WARNINGS_LOG=/tmp/tmp.3UgKi9FCcP
remote: PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkgconfig:/app/.heroku/vendor/lib/pkgconfig:/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:
remote: _=/usr/bin/env
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to habibam.
remote:
To https://git.heroku.com/habibam.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/habibam.git'
It's looking in the directory Nostradamus/static and throwing an error because that directory doesn't exist.
If that directory does exist locally then the problem might be that it's empty and so git doesn't track it. The simple solution to that is to create an empty file called .keep (or anything you like, it doesn't matter what it's called) in that directory which will cause git to "see" it.