简体   繁体   English

python TypeError:必须是没有 NULL 字节的编码字符串,而不是 str - docker iron requirements.txt

[英]python TypeError: must be encoded string without NULL bytes, not str - docker iron requirements.txt

I have been trying to deploy a python script to Iron.io.我一直在尝试将 python 脚本部署到 Iron.io。 They recommend using docker to test locally before uploading.他们建议在上传之前使用 docker 在本地进行测试。

I have completed their provided docker/iron tutorial without error.我已经毫无错误地完成了他们提供的 docker/iron 教程

So I started to modify the provided requirements.txt from their sample repo to start my own project, but whenever I try to install the packages locally I receive a TypeError.所以我开始修改他们的示例存储库中提供的 requirements.txt以启动我自己的项目,但是每当我尝试在本地安装包时,我都会收到 TypeError。

My pip is version:我的 pip 是版本:

pip 7.1.2 from /Library/Python/2.7/site-packages (python 2.7)

Their requirements.txt他们的要求.txt

iron-mq>=0.5
iron-worker>=1.3.1

My requirements.txt我的需求.txt

iron-mq>=0.5
iron-worker>=1.3.1
beautifulsoup4
html5lib

Terminal command:终端命令:

$ docker run --rm -v "$PWD":/worker -w /worker iron/python:2-dev pip install -t packages -r requirements.txt

Error:错误:

Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 282, in run
    wheel_cache
 File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 291, in populate_requirement_set
    wheel_cache=wheel_cache):
 File "/usr/lib/python2.7/site-packages/pip/req/req_file.py", line 89, in parse_requirements
    for req in req_iter:
 File "/usr/lib/python2.7/site-packages/pip/req/req_file.py", line 137, in process_line
    isolated=isolated, options=req_options, wheel_cache=wheel_cache
 File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 168, in from_line
    if (os.path.isdir(p) and
 File "/usr/lib/python2.7/genericpath.py", line 49, in isdir
    st = os.stat(s)
 TypeError: must be encoded string without NULL bytes, not str

I am using Sublime on OSX and encoding with UTF-8.我在 OSX 上使用 Sublime 并使用 UTF-8 编码。 Other threads regarding this error are usually resolved by escaping some characters or changing the encoding.关于此错误的其他线程通常通过转义某些字符或更改编码来解决。 But I couldn't find an alternative encoding to use.但是我找不到要使用的替代编码。

Is there a trick to saving requirements without any null bytes?在没有任何空字节的情况下保存要求有技巧吗? Or is there another known fix?或者还有其他已知的修复方法吗?

Edit update:编辑更新:

Running with -vvv max verbose mode for pip使用 pip 的 -vvv 最大详细模式运行

docker run --rm -v "$PWD":/worker -w /worker iron/python:2-dev pip install -vvv -t packages -r requirements.txt

Returned回来

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 282, in run
    wheel_cache
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 291, in populate_requirement_set
    wheel_cache=wheel_cache):
  File "/usr/lib/python2.7/site-packages/pip/req/req_file.py", line 89, in parse_requirements
    for req in req_iter:
  File "/usr/lib/python2.7/site-packages/pip/req/req_file.py", line 137, in process_line
isolated=isolated, options=req_options, wheel_cache=wheel_cache
  File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 168, in from_line
    if (os.path.isdir(p) and
  File "/usr/lib/python2.7/genericpath.py", line 49, in isdir
    st = os.stat(s)
TypeError: must be encoded string without NULL bytes, not str
Starting new HTTPS connection (1): pypi.python.org
"GET /pypi/pip/json HTTP/1.1" 200 50975

The only new output was the two lines at the bottom.唯一的新输出是底部的两行。

Running iconv to identify any rogue characters just returns the contents of the txt file.运行 iconv 来识别任何恶意字符只会返回 txt 文件的内容。

iconv -t UTF-8 requirements.txt

iron-mq>=0.5
iron-worker>=1.3.1
beautifulsoup4==4.4.1

I had the same trouble trying to run pip install on my Mac with the Iron docker images.我在尝试使用 Iron docker 图像在我的 Mac 上运行pip install时遇到了同样的麻烦。 After trying a bunch of things to fix it, I tracked the problem down to Docker Toolbox and vboxfs.在尝试了很多方法来修复它之后,我将问题追溯到 Docker Toolbox 和 vboxfs。 They weren't syncing host filesystem changes properly.他们没有正确同步主机文件系统更改。 To fix it, in the docker toolbox VM I ran:要修复它,在我运行的 docker 工具箱 VM 中:

sync; echo 3 > /proc/sys/vm/drop_caches

The sync call syncs any pending writes to disk. sync调用将任何挂起的写入同步到磁盘。 The second command tells the kernel to clear the filesystem caches.第二条命令告诉内核清除文件系统缓存。

Once I did that my pip install worked fine.一旦我这样做了,我的pip install工作正常。

On Windows and Mac OS, Docker Daemon runs on a virtual machine.在 Windows 和 Mac OS 上,Docker Daemon 运行在虚拟机上。

Try to enter the virtual machine and run the Docker commands there.尝试进入虚拟机并在那里运行 Docker 命令。 A possible work around for this issue is to avoid running Docker commands on host machine.解决此问题的可能方法是避免在主机上运行 Docker 命令。

As a reminder, Iron.io's support is available via phone, email or chat for additional questions.提醒一下,Iron.io 的支持可以通过电话、电子邮件或聊天来解决其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:file()参数1必须是没有NULL字节的编码字符串,而不是str - TypeError: file() argument 1 must be encoded string without NULL bytes, not str TypeError:必须是不包含空字节的字符串,而不是str - TypeError: must be string without null bytes, not str 训练 '\\x00' s 和 TypeError: stat() 参数 1 必须是没有空字节的编码字符串,而不是 str - Training '\x00' s and TypeError: stat() argument 1 must be encoded string without null bytes, not str TypeError:必须是不包含空字节的字符串,在os.system()中不能为str - TypeError: must be string without null bytes, not str in os.system() 阻止Docker在每个版本上安装python软件包要求(没有requirements.txt) - Prevent Docker from installing python package requirements on every build (without requirements.txt) 包含要安装的软件包的 python 文件是否必须称为 requirements.txt? - Does python file with packages to install must be called requirements.txt? 在 Python3 中解码字节字符串时出错 [TypeError: must be str, not bytes] - Error decoding byte string in Python3 [TypeError: must be str, not bytes] Python中的Requirements.txt文件 - Requirements.txt file in Python Python Django 要求.txt - Python Django requirements.txt 将python项目移动到另一台PC而不使用requirements.txt - move python project to another PC without using requirements.txt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM