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. They recommend using docker to test locally before uploading.

I have completed their provided docker/iron tutorial without error.

  • slow pg_restore on docker container startup
  • How to remove old Docker containers
  • AWS Cloudwatch logs with Docker Container - NoCredentialProviders: no valid providers in chain
  • Mono TLS1.2 issues - btls-cert-sync “command not found”
  • How to show all users in dockers group?
  • Where to find more explicit errors given container error status codes?
  • 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.

    My pip is version:

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

    Their requirements.txt

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

    My requirements.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. 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

    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 -t UTF-8 requirements.txt
    
    iron-mq>=0.5
    iron-worker>=1.3.1
    beautifulsoup4==4.4.1
    

  • Create a docker container with no DNS nameservers in /etc/resolv.conf
  • nginx load balancer IP-requester based
  • Docker, Supervisord and supervisor-stdout
  • Bypass install configuration in dockerfile
  • How to change docker installation directory in centos 7 with docker 1.13 version
  • Dockerize Multi Module Maven Project
  • One Solution collect form web for “python TypeError: must be encoded string without NULL bytes, not str – docker iron requirements.txt”

    I had the same trouble trying to run pip install on my Mac with the Iron docker images. After trying a bunch of things to fix it, I tracked the problem down to Docker Toolbox and vboxfs. They weren’t syncing host filesystem changes properly. To fix it, in the docker toolbox VM I ran:

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

    The sync call syncs any pending writes to disk. The second command tells the kernel to clear the filesystem caches.

    Once I did that my pip install worked fine.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.