question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Unicode-objects must be encoded before hashing on node-gyp (Python 3.6.7)

See original GitHub issue

Environment Information

  • OS [Ubuntu 16.04.5 LTS]: [edited]
  • Node Version [10.18.1]:
  • NPM Version [6.13.4]:
  • C++ Toolchain [gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609]: [edited]
  • node-rdkafka version [2.7.4]:

Steps to Reproduce

Try to build the following Dockefile:

FROM python:3.6.7

RUN apt-get update \
    && apt-get install -y build-essential \
    ca-certificates \
    libsasl2-dev \
    libsasl2-modules \
    libssl-dev

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash && apt install -y nodejs

RUN node -v && npm -v

RUN npm install node-rdkafka

node-rdkafka Configuration Settings

Not needed

Additional context

Hello.

last week, I had a surprise when deploying an app, our build is throwing:

> node-rdkafka@2.7.4 install /home/travis/es/src/.../node_modules/node-rdkafka
> node-gyp rebuild

Traceback (most recent call last):
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 50, in <module>
    sys.exit(gyp.script_main())
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 554, in script_main
    return main(sys.argv[1:])
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 547, in main
    return gyp_main(args)
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 532, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2215, in GenerateOutput
    part_of_all=qualified_target in needed_targets)
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 794, in Write
    extra_mac_bundle_resources, part_of_all)
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 978, in WriteActions
    part_of_all=part_of_all, command=name)
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1724, in WriteDoCmd
    force = True)
  File "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1779, in WriteMakeRule
    cmddigest = hashlib.sha1(command if command else self.target).hexdigest()
TypeError: Unicode-objects must be encoded before hashing

gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.19.52
gyp ERR! command "/home/travis/.nvm/versions/node/v10.18.0/bin/node" "/home/travis/.nvm/versions/node/v10.18.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/travis/es/src/github.ibm.com/CIO-SETS/engage-support/foe-fom/services/node_modules/node-rdkafka
gyp ERR! node -v v10.18.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-rdkafka@2.7.4 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-rdkafka@2.7.4 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/travis/.npm/_logs/2020-01-09T18_26_58_064Z-debug.log

We use travis and it’s python version is 3.6.7, I’ve tested other version and it worked fine on all of them. Which is strange, as 3.6.* is technically supported by node-gyp.

May someone give some light on what can I do? Forcing the use of another python version is something I’ll have to explain to our ops team, so I would rather leave it to a last resort

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
sam-githubcommented, Mar 11, 2020

Looks like this is a node-gyp bug, fixed in https://github.com/nodejs/node-gyp/pull/1925, released in v5.0.6. Use a version of npm that includes that version. I just did an npm install -g npm, got npm 6.14.2:

% npm ls -g node-gyp
/home/sam/.nvm/versions/node/v12.16.1/lib
└─┬ npm@6.14.2
  ├── node-gyp@5.1.0 
  └─┬ npm-lifecycle@3.1.4
    └── node-gyp@5.1.0  deduped

Did an npm install of node-rdkafka, and it fixed the error above.

I believe that should close this issue, its not an issue with this project, and its fixed upstream, and released in npm.

0reactions
stale[bot]commented, Jun 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correct TypeError: Unicode-objects must be encoded ...
It is probably looking for a character encoding from wordlistfile . wordlistfile = open(wordlist,"r",encoding='utf-8').
Read more >
Unicode-Objects Must be Encoded Before Hashing?
The typeError: Unicode-objects must be encoded before hashing error python appears when you try to pass a string to a hashing algorithm ...
Read more >
node-gyp - npm
node -gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It contains a vendored ...
Read more >
Python 3.3 - Unicode-objects must be encoded before hashing
Python 3.3 - Unicode-objects must be encoded before hashing ... datetime as date node = Flask(__name__) class Block: def __init__(self, ...
Read more >
Unicode-objects must be encoded before hashing? - Learn ...
TypeError : Unicode-objects must be encoded before hashing. when I try to execute this code in Python 3.2.2: import hashlib, sys
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found