Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Python error: Py_Initialize: Unable to get the locale encoding #155

Open
cezmunsta opened this issue Aug 5, 2020 · 5 comments
Open

Comments

@cezmunsta
Copy link

cezmunsta commented Aug 5, 2020

After a patch run raising the version to 1.7.3, pdagent fails to start:

$ sudo -u pdagent python3 $(pwd)/1.7.3/usr/share/pdagent/bin/pdagentd.py -f
Fatal Python error: Py_Initialize: Unable to get the locale encoding
LookupError: no codec search functions registered: can't find encoding

Current thread 0x00007f3338f96740 (most recent call first):
Aborted

A change to the systemd unit file means that a shell script is now executed, which attempts to use python3:

$ diff -ruNp 1.17.2/var/lib/pdagent/scripts/pdagent.service 1.7.3/var/lib/pdagent/scripts/pdagent.service
--- 1.17.2/var/lib/pdagent/scripts/pdagent.service      2020-05-06 14:41:21.000000000 +0000
+++ 1.17.3/var/lib/pdagent/scripts/pdagent.service      2020-06-30 15:55:42.000000000 +0000
@@ -6,7 +6,7 @@ After=network.target
 Type=simple
 ExecStartPre=/bin/mkdir -p /var/run/pdagent
 ExecStartPre=/bin/chown -R pdagent:pdagent /var/run/pdagent
-ExecStart=/usr/share/pdagent/bin/pdagentd.py -f
+ExecStart=/usr/share/pdagent/bin/pdagentd -f
 KillMode=process
 TimeoutStopSec=15
 RestartSec=15

$ diff -ruNp 1.17.2/usr/share/pdagent/bin/pdagentd 1.7.3/usr/share/pdagent/bin/pdagentd
--- 1.17.2/usr/share/pdagent/bin/pdagentd       1970-01-01 00:00:00.000000000 +0000
+++ 1.17.3/usr/share/pdagent/bin/pdagentd       2020-06-30 15:55:42.000000000 +0000
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+
+if [ -x "$(command -v python3)" ];
+then
+    python3 $DIR/pdagentd.py "$@"
+else
+    python $DIR/pdagentd.py "$@"
+fi

Package from main repo:

$ repoquery --location pdagent
https://packages.pagerduty.com/pdagent/rpm/pdagent-1.7.3-1.noarch.rpm

Additional info:

$ cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

$ rpm -q --whatprovides /usr/bin/python3
python3-3.6.8-13.el7.x86_64

One odd thing is that I don't see a 1.7.3 tag here on this repo

@blagh
Copy link

blagh commented Aug 5, 2020

Hi there 🤔 the latest released version of pdagent is 1.7.2 -- where are you getting these version numbers? Do they reference something else?

@cezmunsta
Copy link
Author

cezmunsta commented Aug 5, 2020

Hi there the latest released version of pdagent is 1.7.2 -- where are you getting these version numbers? Do they reference something else?

Thanks for the quick reply. The version is as per the package direct from the repo:

$ repoquery --location pdagent
https://packages.pagerduty.com/pdagent/rpm/pdagent-1.7.3-1.noarch.rpm

I noticed that a release version was missing here though

One odd thing is that I don't see a 1.17.3 tag here on this repo

Here is the content of __init__.py:

$ cat usr/lib/python3.7/site-packages/pdagent/__init__.py 
#
# Copyright (c) 2013-2014, PagerDuty, Inc. <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#   * Neither the name of the copyright holder nor the
#     names of its contributors may be used to endorse or promote products
#     derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

__version__ = "1.7.3"

def enum(*sequential, **named):
    enums = dict([x[::-1] for x in enumerate(sequential)], **named)
    return type('Enum', (), enums)

I fixed the typo made on the dirnames that confused matters futher :)

@cezmunsta
Copy link
Author

For reference:

$ sudo rpm --checksig -v pdagent-1.7.3-1.noarch.rpm
pdagent-1.7.3-1.noarch.rpm:
    Header V4 RSA/SHA1 Signature, key ID 7375a2b7: OK
    Header SHA1 digest: OK (093433c56450270f90e9010ef40985f483382ace)
    V4 RSA/SHA1 Signature, key ID 7375a2b7: OK
    MD5 digest: OK (ab6f609a0c0c346aadc9e7f8eaf6463a)

@blagh
Copy link

blagh commented Aug 5, 2020

Ahh ok. I believe these are changes in progress in this pull request that haven't been merged yet: #153

For the moment I'd recommend sticking with 1.7.2 as those changes haven't been 100% sorted out yet. I'll look into why the package was shipped.

@cezmunsta
Copy link
Author

For the moment I'd recommend sticking with 1.7.2 as those changes haven't been 100% sorted out yet. I'll look into why the package was shipped.

Thanks for the quick response, I've merged a change that pins to 1.7.2 in our automation code already, so resolved internally for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants