小编Jus*_*ory的帖子

"TypeError:没有编码的字符串参数",但字符串是否已编码?

我正在努力将现有程序从Python2 转换为Python3.程序中的一种方法使用远程服务器对用户进行身份验证.它会提示用户输入密码.

def _handshake(self):
    timestamp = int(time.time())
    token = (md5hash(md5hash((self.password).encode('utf-8')).hexdigest()
                + str(bytes('timestamp').encode('utf-8'))))
    auth_url = "%s/?hs=true&p=1.2&u=%s&t=%d&a=%s&c=%s" % (self.name,
                                                          self.username,
                                                          timestamp,
                                                          token,
                                                          self.client_code)
    response = urlopen(auth_url).read()
    lines = response.split("\n")
    if lines[0] != "OK":
        raise ScrobbleException("Server returned: %s" % (response,))
    self.session_id = lines[1]
    self.submit_url = lines[3]
Run Code Online (Sandbox Code Playgroud)

此方法的问题是在将整数转换为字符串后,需要对其进行编码.但据我所知,它已经编码了?我发现了这个问题,但我很难将其应用到该程序的上下文中.

这是给我带来问题的路线.

  • + str(bytes('timestamp').encode('utf-8'))))
    • TypeError: string argument without an encoding

我尝试过使用其他方法来解决这个问题,所有这些都有不同类型的错误.

  • + str(bytes('timestamp', 'utf-8'))))
    • TypeError: Unicode-objects must be encoded before hashing
  • + str('timestamp', 'utf-8')))
    • TypeError: decoding str is not supported

我还在开始学习Python(但我初学到Java的中级知识),所以我还不完全熟悉这门语言.有没有人对这个问题有什么想法?

谢谢!

python string encoding utf-8 python-3.x

5
推荐指数
1
解决办法
2万
查看次数

无法在 Docker 容器中执行二进制文件(“不允许操作”)

问题

我正在构建一个 Docker 容器(基于 RHEL),其中包含来自第三方存储库的自定义二进制文件。在容器中执行二进制文件时,我收到一个不起眼的错误:“ Operation not permitted”。

分析

Dockerfile

Dockerfile 相当简单。

FROM dockerregistry.example.com/rhel7:latest

RUN yum -y install \
    curl \
    custom-package && \
    curl -Lsq https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 > /sbin/dumb-init && \
    chmod 755 /sbin/dumb-init && \
    yum clean all

ADD custom-package.conf /etc/custom-package/custom-package.conf

ENTRYPOINT ["/sbin/dumb-init", "--"]
CMD ["/usr/local/custom-package/bin/custom-package", "--config", "/etc/custom-package/custom-package.conf"]
Run Code Online (Sandbox Code Playgroud)

塑造形象

我使用以下命令在我的工作站上构建并输入容器。

$ docker build -t custom-package:v1 .
$ docker run --security-opt seccomp:unconfined -d custom-package:v1 tail -f /dev/null
$ docker exec -it <image ID> /bin/bash
Run Code Online (Sandbox Code Playgroud)

“不允许操作”

一旦我进入图像,如果我尝试执行二进制文件,我会收到一个极其无用的错误。运行strace也会产生令人困惑的输出。在检查文件权限和元数据时,似乎没问题。

# …
Run Code Online (Sandbox Code Playgroud)

bash centos rhel docker dockerfile

3
推荐指数
1
解决办法
6099
查看次数

标签 统计

bash ×1

centos ×1

docker ×1

dockerfile ×1

encoding ×1

python ×1

python-3.x ×1

rhel ×1

string ×1

utf-8 ×1