docker-compose up: utf-8 codec can't decode byte X - python

Everytime I run docker-compose up on my machine (macOS 10.13.5, latest docker version) I get this error
Traceback (most recent call last): File "docker-compose", line 6, in
File "compose/cli/main.py", line 71, in main File
"compose/cli/main.py", line 124, in perform_command File
"compose/cli/command.py", line 41, in project_from_options File
"compose/cli/command.py", line 126, in get_project File
"compose/project.py", line 96, in from_config File
"compose/network.py", line 320, in get_networks File
"compose/network.py", line 125, in true_name File
"compose/network.py", line 146, in _set_legacy_flag File
"compose/network.py", line 106, in inspect File
"site-packages/docker/utils/decorators.py", line 19, in wrapped File
"site-packages/docker/api/network.py", line 211, in inspect_network
File "site-packages/docker/utils/decorators.py", line 46, in inner
File "site-packages/docker/api/client.py", line 194, in _get File
"site-packages/requests/sessions.py", line 521, in get File
"site-packages/requests/sessions.py", line 494, in request File
"site-packages/requests/sessions.py", line 424, in prepare_request
File "site-packages/requests/utils.py", line 195, in get_netrc_auth
File "netrc.py", line 33, in init File "netrc.py", line 42, in
_parse File "shlex.py", line 105, in get_token File "shlex.py", line 136, in read_token File
"/Users/distiller/compose-osx-release/compose/venv/lib/python3.6/codecs.py",
line 321, in decode UnicodeDecodeError: 'utf-8' codec can't decode
byte 0x80 in position 33: invalid start byte

Ok so apparently there is a problem with the current version of docker-compose for macOS... It's just my guess, but anyhow here is how I solved it
curl -L https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
Then restarted the terminal

I ran into this same issue and this may also be related to your .env files.
Ensure that your .env files are UTF-8.
sudo apt install moreutils
isutf8 yourfile.env
If isutf8 returns no output it's likely a valid UTF-8 file.
Additionally, check the contents of the .env file you're referencing in your docker-compose.yml. Any incorrectly decrypted secrets/values you may be using locally can cause this problem too.
If in doubt, clear the env file and readd lines until you hit the error.

I have 2 ideas:
1. try to reinstall your python
2. use not the latest docker version, but the latest stable

What worked for me was creating an empty .env file in the directory I run docker-compose in (encoded as UTF-8).

you need to go to the pycharm env file, double click it and install the python env file. Then run the code [docker-compose up airflow-init] again, it'll work.

Related

I stumbled upon "UnicodeDecodeError:" after running "python -m pipreqs.pipreqs . " on VSC terminal

I wanted to generate requirements.txt of only used packages in a given project. pip freeze works fine but saves all packages in the environment including those that you don't use in your current project, and once you have a bunch of installed packages, it become tedious deleting manually the packages that aren't required for the current project.
I tried pipreqs which is supposed to generate requirements.txt based on used packages in the current project, by running the below approaches in terminal but they throw the same error:
$ python -m pipreqs.pipreqs .
$ pipreqs
$ pipreqs /project/location
Error:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\Scripts\pipreqs.exe\__main__.py", line 7, in <module>
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\lib\site-packages\pipreqs\pipreqs.py", line 488, in main
init(args)
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\lib\site-packages\pipreqs\pipreqs.py", line 415, in init
candidates = get_all_imports(input_path,
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\lib\site-packages\pipreqs\pipreqs.py", line 115, in get_all_imports
contents = f.read()
File "C:\Program Files\Python39\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 1237: character maps to <undefined>
Could anyone help spot the error?
At the point where the crash is happening, pipreqs is thinking that your input is cp1252 but the data contains a character that is not supported within that character set/encoding (eg, byte 0x8d).
You could try passing --encoding argument and experiment with different values (like utf-8 or utf-16)
Even though #rasjani spotted a significant point of the cause of the error, when I implemented the rule, a new error popped up again and took me quite some couple of minutes to reflex. Here was what happened.
$ pipreqs --encoding=utf8 C:\Users\myProjects\dataScience\sp_app\advance_app
New Error:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\Scripts\pipreqs.exe\__main__.py", line 7, in <module>
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\lib\site-packages\pipreqs\pipreqs.py", line 488, in main
init(args)
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\lib\site-packages\pipreqs\pipreqs.py", line 478, in init
generate_requirements_file(path, imports, symbol)
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\lib\site-packages\pipreqs\pipreqs.py", line 157, in generate_requirements_file
with _open(path, "w") as out_file:
File "C:\Program Files\Python39\lib\contextlib.py", line 117, in __enter__
return next(self.gen)
File "C:\Users\myProjects\dataScience\sp_app\advance_app\venv\lib\site-packages\pipreqs\pipreqs.py", line 81,
in _open
file = open(filename, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'C:UsersmyProjectsdataSciencesp_appadvance_appsrcpackagesadvance_app\\requirements.txt'
Note: The reason why this happen is because I used single \ for the path instead of \\.
Solution:
$ pipreqs --encoding=utf8 C:\\Users\\myProjects\\dataScience\\sp_app\\advance_app
Output:
INFO: Successfully saved requirements file in C:\Users\myProjects\dataScience\sp_app\advance_app\requirements.txt

Command '['git' 'clone', '--recurse-submodules', '--', 'ssh://git#git/b2b/py_client.git'] returned non-zero exit status 128

I am trying to create virtualenv with make setup and poetry in Git Bash:
$ make setup
poetry install --no-root
Creating virtualenv ad-ml in C:\Users\user1\Documents\ad_ml\.venv
Installing dependencies from lock file
Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting outdated dependencies. Run update to update them.
CalledProcessError
Command '['C:\\Users\\user1\\AppData\\Local\\Programs\\Git\\mingw64\\bin\\git.exe'
, 'clone', '--recurse-submodules', '--', 'ssh://git#git.bcb.local:7999/b2b/py_client.git',
'C:\\Users\\EMANZH~1\\AppData\\Local\\Temp\\pypoetry-git-py_clien9fdvh9lr']'
returned non-zero exit status 128.
at ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\_compat.py:217 in run
and get CalledProcessError with exit status 128 and another exception:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user1\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\user1\Anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\user1\AppData\Roaming\Python\Scripts\poetry.exe\__main__.py", line 7, in <module>
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\__init__.py", line 5, in main
return Application().run()
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\console_application.py", line 142, in run
trace.render(io, simple=isinstance(e, CliKitException))
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 232, in render
return self._render_exception(io, self._exception)
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 269, in _render_exception
self._render_snippet(io, current_frame)
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 289, in _render_snippet
self._render_line(io, code_line)
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\ui\components\exception_trace.py", line 402, in _render_line
io.write_line("{}{}".format(indent * " ", line))
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\io\io_mixin.py", line 65, in write_line
super(IOMixin, self).write_line(string, flags)
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\io.py", line 66, in write_line
self._output.write_line(string, flags=flags)
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\output.py", line 69, in write_line
self.write(string, flags=flags, new_line=True)
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\api\io\output.py", line 61, in write
self._stream.write(to_str(formatted))
File "C:\Users\user1\AppData\Roaming\pypoetry\venv\lib\site-packages\clikit\io\output_stream\stream_output_stream.py", line 24, in write
self._stream.write(string)
File "C:\Users\user1\Anaconda3\lib\encodings\cp1251.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2502' in position 27: character maps to <undefined>
Are there any ideas how to fix this error, any help would be much appreciated.
pc windows 10, git bash 2.34.0, cloned repo with sourcetree from bitbucket, python 3.8.8
Check first if this is similar to python-poetry/poetry issue 3297, which refers to a pypa/virtualenv issue 1986
The first link includes (by Daniel Taylor):
We downgrade virtualenv inside the conda environment in our circle CI windows executors, not sure if it with pip or not.
So adding a step like this to your yml config should fix the issue (or just adding virtualenv=20.0.33 to the step where you install your conda dependencies):
- run: conda install virtualenv=20.0.33
The OP Taky proposes in the comments:
I changed dependency link to py_client.git in pyproject.toml from "ssh" to "https", and that's worked for me.

use pipenv -h, UnicodeDecodeError: 'utf-8'

use pipenv -h and other commands like --venv -install, UnicodeDecodeError: 'utf-8', pipenv commands are error.And i can't find answers in other places.
F:\proc_py\pipEnv>pipenv -h
Traceback (most recent call last):
File "e:\python3.6\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "e:\python3.6\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:\python3.6\Scripts\pipenv.exe\__main__.py", line 5, in <module>
File "e:\python3.6\lib\site-packages\pipenv\__init__.py", line 47, in <module>
from .cli import cli
File "e:\python3.6\lib\site-packages\pipenv\cli\__init__.py", line 3, in <modu
le>
from .command import cli
File "e:\python3.6\lib\site-packages\pipenv\cli\command.py", line 7, in <modul
e>
import crayons
File "e:\python3.6\lib\site-packages\pipenv\patched\crayons.py", line 49, in <
module>
is_powershell = "powershell" in shellingham.detect_shell()[0]
File "e:\python3.6\lib\site-packages\pipenv\vendor\shellingham\__init__.py", l
ine 22, in detect_shell
shell = get_shell(pid, max_depth=max_depth)
File "e:\python3.6\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 10
0, in get_shell
processes = dict(_iter_process())
File "e:\python3.6\lib\site-packages\pipenv\vendor\shellingham\nt.py", line 78
, in _iter_process
info = {'executable': str(pe.szExeFile.decode('utf-8'))}
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 0: invalid
start byte
I do not know why, pipenv commands are error.And i can't find answers in other places.
I've met same problem and was lurking internet for a solution but having not much time and figured out some possible workaround for making it
I was tryin to install PIPEnvironment through Pycharm interpreter settings and problem occured:
Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\decorators.py", line 17, in new_func
[pipenv.exceptions.VirtualenvCreationException]: return f(get_current_context(), *args, **kwargs)
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\pipenv\cli\command.py", line 208, in cli
[pipenv.exceptions.VirtualenvCreationException]: clear=state.clear,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]: File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
File "C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\virtualenv.py", line 939, in call_subprocess
line = line.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 280: invalid continuation byte
I went to a file
"C:\Users\ogmamedo\AppData\Roaming\Python\Python37\site-packages\virtualenv.py"
And changed code like this:
encoding = sys.getdefaultencoding()
fs_encoding = 'OEM' #sys.getfilesystemencoding()
This helped me to pass that stage (first 10 seconds) when bug was occuring.
Why it's 'OEM'?
Because as we see in that file - there are a call to a system prompt (cmd shell), and my system's cmd shell has encoding 'OEM'.
I'll point that this is a workaround, not a proper solution, but due to a lack of time and interest figuring out which of sides this bug belongs to (pycharm or pipenv) I wont continue to a proper solution.

UnicodeDecodeError when instaling new package

I am trying to install a package that I have used many times with python 2.7 and ubuntu 14.04, however it fails now with following error:
Cleaning up…
Exception:
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/pip/basecommand.py”, line 122, in main
status = self.run(options, args)
File “/usr/lib/python2.7/dist-packages/pip/commands/install.py”, line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File “/usr/lib/python2.7/dist-packages/pip/req.py”, line 1198, in prepare_files
do_download,
File “/usr/lib/python2.7/dist-packages/pip/req.py”, line 1376, in unpack_url
self.session,
File “/usr/lib/python2.7/dist-packages/pip/download.py”, line 582, in unpack_http_url
unpack_file(temp_location, location, content_type, link)
File “/usr/lib/python2.7/dist-packages/pip/util.py”, line 643, in unpack_file
untar_file(filename, location)
File “/usr/lib/python2.7/dist-packages/pip/util.py”, line 574, in untar_file
path = os.path.join(location, fn)
File “/usr/lib/python2.7/posixpath.py”, line 80, in join
path += ‘/’ + b
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe2 in position 47: ordinal not in range(128)
Storing debug log for failure in /home/ubuntu/.pip/pip.log
I googled around and it supposed to be a locale error, I managed to set locale to en_us.utf-8 it didn’t change anything. I don’t understand much about these settings, so I don’t know what to do next.
Could anybody help me out with this?
The package name is AllAuth and it fails with any version, new old, everything fails.
Try this executing
export PYTHONIOENCODING=utf8
try this link. Might be helpful for you.
Make sure that the package you're trying to install is Python 2 compatible. More and more modules are migrated to Python 3 and the new version handles unicode characters differently than version 2.

Google AppEngine Python OSError "too many files open" at launch

I'm using ubuntu 13.10 running in a VM on OSX, python2.7 and GAE 1.8.8.
Lauching dev_appserver.py results in the following error:
INFO 2013-12-10 03:53:30,046 api_server.py:527] Saving search indexes
Traceback (most recent call last):
File "/home/ubuntu/xxxxxx/google_appengine/dev_appserver.py", line 197, in <module>
File "/home/ubuntu/xxxxxx/google_appengine/dev_appserver.py", line 193, in _run_file
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 872, in <module>
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 868, in main
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 707, in stop
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 141, in quit
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 528, in cleanup_stubs
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/api/search/simple_search_stub.py", line 984, in Write
File "/usr/lib/python2.7/tempfile.py", line 304, in mkstemp
File "/usr/lib/python2.7/tempfile.py", line 239, in _mkstemp_inner
OSError: [Errno 24] Too many open files: '/tmp/appengine.xxxxxx-hr-dev.ubuntu/tmpMVVXrH'
Any ideas?
Check the shared memory parameter, kern.sysv.shmseg on your linux system and set it right by increasing it.
To view the shared memory parameters, use:
sysctl -A | grep shm
To update that parameters, edit file:
sudo nano /etc/sysctl.conf
Refer to this SO answer for more information.

Categories

Resources